fork download
  1. #include<iostream>
  2. #include<map>
  3. #include<vector>
  4.  
  5. using namespace std;
  6.  
  7. struct tnode {
  8. tnode *parent;
  9. int data;
  10. int circlesize;
  11. };
  12.  
  13. int main(void) {
  14. int N;
  15. cin >> N;
  16. for (int i = 0; i < N; i++) {
  17. int n, m;
  18. cin >> n >> m;
  19. map<int, tnode*> member;;
  20. for (int j = 1; j < n+1; j++) {
  21. tnode *tmp;
  22. tmp = new tnode;
  23. tmp->data = j;
  24. tmp->parent = tmp;
  25. tmp->circlesize = 1;
  26. member[j] = tmp;
  27. }
  28. for (int j = 0; j < m; j++) {
  29. int a, b;
  30. cin >> a >> b;
  31. if (member[a]->circlesize > member[b]->circlesize) {
  32. member[b]->parent = member[a];
  33. member[a]->circlesize += 1;
  34. }
  35. else {
  36. member[a]->parent = member[b];
  37. member[b]->circlesize += 1;
  38. }
  39. }
  40. int ans;
  41. ans = member[1]->circlesize;
  42. for (int j = 2; j < n + 1; j++) {
  43. if (ans < member[j]->circlesize) {
  44. ans = member[j]->circlesize;
  45. }
  46. }
  47. cout << ans << endl;
  48. }
  49. }
Success #stdin #stdout 0s 4488KB
stdin
Standard input is empty
stdout
Standard output is empty