#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> graph(n + 1);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
graph[b].push_back(a);
}
vector<int> result(n + 1);
int maxCount = 0;
for (int i = 1; i <= n; i++) {
vector<bool> visited(n + 1, false);
queue<int> q;
q.push(i);
visited[i] = true;
int count = 1;
while (!q.empty()) {
int cur = q.front();
q.pop();
for (int next : graph[cur]) {
if (!visited[next]) {
visited[next] = true;
q.push(next);
count++;
}
}
}
result[i] = count;
maxCount = max(maxCount, count);
}
for (int i = 1; i <= n; i++) {
if (result[i] == maxCount) {
cout << i << " ";
}
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: