-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy path[15]_3.cpp
52 lines (48 loc) · 877 Bytes
/
[15]_3.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
#include <bits/stdc++.h>
using namespace std;
int n, m, max_value;
vector<int> adj[10001];
bool visited[10001];
vector<int> result;
int bfs(int x) {
queue<int> q;
q.push(x);
memset(visited, false, sizeof(visited));
visited[x] = true;
int cnt = 1;
while (!q.empty()) {
int now = q.front();
q.pop();
for (int i = 0; i < adj[now].size(); i++) {
int y = adj[now][i];
if (!visited[y]) {
q.push(y);
visited[y] = true;
cnt++;
}
}
}
return cnt;
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
adj[y].push_back(x);
}
for (int i = 1; i <= n; i++) {
int cnt = bfs(i);
if (cnt > max_value) {
result.clear();
result.push_back(i);
max_value = cnt;
}
else if (cnt == max_value) {
result.push_back(i);
}
}
for (int i = 0; i < result.size(); i++) {
cout << result[i] << ' ';
}
}