Professional Documents
Culture Documents
Int Long Int Long Int Int Int Int Int Int: Using Namespace Class
Int Long Int Long Int Int Int Int Int Int: Using Namespace Class
#include
#include
#include
#include
UnionFind.html
<iostream>
<vector>
<map>
<set>
1/2
01/12/2016
UnionFind.html
id[j] = i;
sz[i] += sz[j];
}
v[i] = v[j] = m.insert(new_val);
cnt--;
}
bool connected(int x, int y)
{
return find(x) == find(y);
}
int count()
{
return cnt;
}
long int top() const
{
return *m.begin();
}
/*void print()
{
for (int i = 0; i < v.size(); i++)
cout << *v[i] << " ";
cout << "\n";
}*/
};
int main()
{
ios::sync_with_stdio(false);
int n, q, k, u, v;
cin >> n >> q;
UF uf(n);
for (int i = 0; i < q; i++)
{
cin >> u >> v;
uf.merge(u - 1, v - 1);
cout << uf.top() << "\n";
//uf.print();
}
return 0;
}
le:///mnt/E/My%20Documents/Desktop/UnionFind.html
2/2