提交时间:2024-01-21 18:56:32
运行 ID: 121440
#include <bits/stdc++.h> using namespace std; struct node { int id, father, son; }a[110]; bool cmp(node x , node y) { return x.son > y.son; } int main() { int n , m; cin >> n >> m; while(m--) { int x , y; cin >> x >> y; a[x].id = x; a[x].son++; a[y].id = y; a[y].father = x; } sort(a + 1 , a + 1 + n , cmp); for(int i = 1; i <= n; i++) if(a[i].father == 0) cout << a[i].id << " "; cout << a[1].id; return 0; }