Skip to content

Commit f4be7b2

Browse files
authoredMay 11, 2021
[ADD] 1325-cpp solution
1 parent dfc2cf0 commit f4be7b2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
 
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Authored by : seastar105
2+
// Co-authored by : -
3+
// Link : http://boj.kr/1b2b0b0081d042e2a24298d188de8ba1
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
int N, M;
7+
vector<vector<int>> G(100005);
8+
bool vis[100005];
9+
int comp_cnt;
10+
11+
void dfs(int cur) {
12+
vis[cur] = true;
13+
++comp_cnt;
14+
for (const int &nxt : G[cur]) {
15+
if (!vis[nxt]) dfs(nxt);
16+
}
17+
}
18+
19+
int main() {
20+
cin.tie(nullptr);
21+
ios::sync_with_stdio(false);
22+
cin >> N >> M;
23+
for (int i = 0; i < M; ++i) {
24+
// u v가 주어지면 v가 해킹됐을 때 u도 해킹된다.
25+
int u, v;
26+
cin >> u >> v;
27+
G[v].push_back(u);
28+
}
29+
vector<int> ans;
30+
int max_cnt = -1;
31+
for (int i = 1; i <= N; ++i) {
32+
memset(vis, false, N + 1);
33+
comp_cnt = 0;
34+
dfs(i);
35+
if (max_cnt < comp_cnt) {
36+
max_cnt = comp_cnt;
37+
ans.clear();
38+
ans.push_back(i);
39+
}
40+
else if (max_cnt == comp_cnt) ans.push_back(i);
41+
}
42+
for (const int &x : ans) cout << x << ' ';
43+
cout << '\n';
44+
return 0;
45+
}

0 commit comments

Comments
 (0)
Please sign in to comment.