fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int find_root(int x, vector<int> &p){
  4. if(p[x] == -1) return x;
  5. else{
  6. p[x] = find_root(p[x], p);
  7. return p[x];
  8. }
  9. }
  10. signed main(){
  11. ios::sync_with_stdio(false);
  12. int n, m;
  13.  
  14. while(cin >> n >> m){
  15. int mx = 1;
  16. vector<int> I_am_your_father(n, -1);
  17. vector<int> len(n, 1);
  18. for(int i = 0; i < m; i++){
  19. int a, b;
  20. cin >> a >> b;
  21. int root_a = find_root(a, I_am_your_father);
  22. int root_b = find_root(b, I_am_your_father);
  23. if(root_a != root_b){
  24. len[root_a] += len[root_b];
  25. I_am_your_father[root_b] = root_a;
  26. mx = max(mx, len[root_a]);
  27. }
  28. }
  29. // for(int i = 0; i < n; i++){
  30. // cout << I_am_your_father[i] << " ";
  31. // }cout << endl;
  32. cout << mx << endl;
  33.  
  34.  
  35.  
  36. }
  37. }
Success #stdin #stdout 0.01s 11240KB
stdin
6 4
0 1
2 3
1 3
5 4
1000000 0
1000000 1
0 999999
stdout
4
1
2