-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathket_ban.cpp
More file actions
67 lines (62 loc) · 1.05 KB
/
Copy pathket_ban.cpp
File metadata and controls
67 lines (62 loc) · 1.05 KB
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
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, res;
vector<vector<int>> G;
bool visited[100000];
void inp()
{
res = 0;
cin >> n >> m;
G.assign(n + 1, {});
memset(visited, 0, sizeof(visited));
for (int i = 1; i <= m; ++i)
{
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
}
void bfs(int s)
{
int length = 1;
queue<int> q;
q.push(s);
visited[s] = true;
while (!q.empty())
{
u = q.front();
q.pop();
for (int v : G[u])
{
if (!visited[v])
{
length++;
q.push(v);
visited[v] = true;
}
}
}
res = max(res, length);
}
void solve()
{
for (int i = 1; i <= n; ++i)
{
if (!visited[i])
{
bfs(i);
}
}
cout << res << endl;
}
int main()
{
int t;
cin >> t;
while (t--)
{
inp();
solve();
}
return 0;
}