File tree 1 file changed +45
-0
lines changed
solution/graph_traversal/1325
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments