-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10608 Friends2.cpp
58 lines (54 loc) · 1.64 KB
/
10608 Friends2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define Set(v,d) memset(v, d, sizeof(v))
#define oo 10000000000000007 //infinity
#define F first
#define S second
#define pb push_back
#define sz(x) (int)(x.size())
#define all(x) (x.begin()), (x.end())
#define rall(x) (x.rbegin()), (x.rend())
typedef vector<int> vi;
const int MAX = 500005;
vi adjList[MAX]; bool visited[MAX]; int ans, num;
void dfs(int n){
visited[n] = 1;
num++;
for(int i=0;i<sz(adjList[n]);i++){
if(!visited[adjList[n][i]]){
dfs(adjList[n][i]);
}
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int TC, n, m;
scanf("%d", &TC);
while(TC--){
for(int i=0;i<MAX;i++)
adjList[i].clear();
ans = 0;
Set(visited, 0);
scanf("%d%d", &n, &m);
for(int i=0;i<m;i++){
int f, t;
scanf("%d%d", &f, &t);
adjList[f].pb(t);
adjList[t].pb(f);
}
for(int i=1;i<=n;i++){
if(!visited[i]){
num = 0;
dfs(i);
ans = max(num, ans);
}
}
cout<<(ans==1? 0 : ans)<<endl;
}
return 0;
}