-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1325.cpp
More file actions
47 lines (45 loc) · 1019 Bytes
/
1325.cpp
File metadata and controls
47 lines (45 loc) · 1019 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
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
typedef pair<int, int> PAIR;
vector<int> adj[10004];
int F[10004];
int mx = 0;
int N, M;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
while (M--) {
int a, b;
cin >> a >> b;
adj[b].push_back(a);
}
for (int st = 1; st <= N; st++) { // st를 해킹할것임
bool isVisited[10005] = {
0,
};
isVisited[st] = true;
stack<int> S;
S.push(st);
int cnt = 1;
while (!S.empty()) {
int cur = S.top();
S.pop();
for (auto near : adj[cur]) {
if (!isVisited[near]) {
isVisited[near] = true;
S.push(near);
cnt++;
}
}
}
F[st] = cnt;
mx = max(mx, cnt);
}
for (int i = 1; i <= N; i++) {
if (F[i] == mx)
cout << i << ' ';
}
}