-
Notifications
You must be signed in to change notification settings - Fork 0
/
ket_ban.cpp
47 lines (46 loc) · 866 Bytes
/
ket_ban.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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
vector<int> adj[100001];
bool visited[100001];
int ans,dem;
void inp(){
ans = 0;
dem = 0;
cin >> n >> m;
memset(adj,0, sizeof(adj));
memset(visited,false, sizeof(visited));
for(int i = 0 ; i < m ; i++){
int x,y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
}
void DFS(int u){
dem++;
visited[u] = true;
for(int v : adj[u]){
if(!visited[v]){
DFS(v);
}
}
}
void solve(){
for(int i = 1;i <= n;i++){
if(!visited[i]){
DFS(i);
ans = max(ans, dem);
dem = 0;
}
}
cout<<ans<<endl;
}
int main(){
int t; cin >>t;
while(t--){
inp();
solve();
}
}