fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,m;
  4. vector<int> ke[1001];
  5. bool visited[1001];
  6. int ans = 0 ;
  7. void inp(){
  8. cin >> n >> m ;
  9. for(int i = 1 ; i <= m ; i ++){
  10. int x,y;
  11. cin >> x >> y;
  12. ke[x].push_back(y);
  13. ke[y].push_back(x);
  14. }
  15. }
  16. void DFS(int u){
  17. visited[u] = true;
  18. for(int x : ke[u]){
  19. if(!visited[x]){
  20. DFS(x);
  21. }
  22. }
  23. ans++;
  24. }
  25. int main(){
  26. inp();
  27. int _max = INT_MIN;
  28. for(int i = 1 ; i <= n ; i++){
  29. ans = 0 ;
  30. DFS(i);
  31. _max = max(_max,ans);
  32. }
  33. cout << _max;
  34. }
  35.  
Success #stdin #stdout 0s 5300KB
stdin
10 6
8 2
4 1
8 6
8 7
8 1
8 5
stdout
7