-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
43 lines (34 loc) · 716 Bytes
/
test.cpp
File metadata and controls
43 lines (34 loc) · 716 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 100005;
vector<int> g[MAXN];
int n, m;
bool vis[MAXN];
int dfs(int u) {
vis[u] = true;
int cnt = 1;
for (int v : g[u]) {
if (!vis[v]) {
cnt += dfs(v);
}
}
return cnt;
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
ans = max(ans, dfs(i));
}
}
cout << ans << endl;
return 0;
}