Esempio n. 1
0
vvii mst(int V, viii &E) {
    vvii G(V);
    union_find uf(V);
    sort(E.begin(), E.end());
    iter(it, E) {
        int x = (*it).S.F;
        int y = (*it).S.S;
        if(uf.unite(x, y)) {
            G[x].push_back(ii(y, (*it).F));
            G[y].push_back(ii(x, (*it).F));
        }
    }
Esempio n. 2
0
	int w(int current_time){
		current_time = current_time  % 1440;
		for (int i = 0; i < t.size(); ++i)
			if(current_time >= t[i].second.first && current_time < t[i].second.second)
				return t[i].first;
		return -1;
	}
 lld kruskal(lld idx) {
   UnionFind UF(n);
   vii MST; //Contiene las aristas del MST
   sort(edges.begin(), edges.end());
   lld mx = -INF;
   for (lld i = idx; i < edges.size(); i++) {
     lld w = edges[i].fst;
     lld a = edges[i].snd.fst;
     lld b = edges[i].snd.snd;
     if (!UF.isSameSet(a, b)) {
       MST.push_back(edges[i].snd);
       mx = max(mx, w);
       UF.Union(a, b);
     }
   }
   //Existencia de MST:
   return (UF.numSet() != 1) ? -1 : mx; // costo del MST
 }
vii kruskal(viii &edges, int n, int m) {
	vii ret;
	UnionFind ds(n);

	sort(edges.begin(), edges.end());

	for (int i = 0; i < m; i++) {
		int w = edges[i].st;
		int u = edges[i].nd.st;
		int v = edges[i].nd.nd;

		if (ds._find(u) != ds._find(v)) {
			ds._union(u, v);
			ret.push_back({min(u, v), max(u, v)});
		}
	}

	return ret;
}
Esempio n. 5
0
File: 105.cpp Progetto: yongduek/UVa
void print (viii& p) {
    for (int i=0; i<p.size(); i++)
        printf (" %d  %d-%d\n", p[i].first, p[i].second.first, p[i].second.second);
    printf("---\n");
}
 void connect(lld a, lld b, lld cost) {
   edges.push_back(make_pair(cost, ii(a, b)));
 }