-
Notifications
You must be signed in to change notification settings - Fork 0
/
1325.cpp
49 lines (45 loc) · 947 Bytes
/
1325.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
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<int> graph[10001];
queue<int> re[10001];
queue<int> q;
int BFS(int s){
int cnt=0;
int visited[10001]={0};
q.push(s);
visited[s]=1;
while(!q.empty()){
int v=q.front();
q.pop();
for(int i=0;i<graph[v].size();i++){
if(visited[graph[v][i]]==0){
q.push(graph[v][i]);
visited[graph[v][i]]=1;
cnt++;
}
}
}
return cnt;
}
int main(){
int N,M; cin>>N>>M;
int mcnt=0;
for(int i=0; i<M; i++){
int a,b; cin >> a>>b;
graph[b].push_back(a);
}
for(int i=1; i<=N;i++){
int cnt = BFS(i);
if(mcnt<=cnt){
mcnt=cnt;
re[mcnt].push(i);
}
}
int j= re[mcnt].size();
for(int i=0; i<j;i++){
cout<<re[mcnt].front()<<" ";
re[mcnt].pop();
}
}