intKruskal(int n, int m){ init(n); sort(edge + 1, edge + 1 + m, cmp); int ans = 0; for(int i = 1; i <= m; ++i) { int x = find(edge[i].u); int y = find(edge[i].v); if(x != y) { ans += edge[i].w; far[x] = y; } } return ans; }
intmain(){ ios::sync_with_stdio(false); int n; while(cin >> n && n) { int m = n * (n - 1) / 2; for(int i = 1; i <= m; ++i) { int f; cin >> edge[i].u >> edge[i].v >> edge[i].w >> f; if(f) { edge[i].w = 0; } } cout << Kruskal(n, m) << endl; } return0; }