提交时间:2024-01-22 08:34:58
运行 ID: 121610
#include <bits/stdc++.h> using namespace std; int n , m , x , y , ans , mx; struct tree { int id, father, son; } t[110]; inline bool cmp(tree a, tree b) { return a.son > b.son; } int main() { cin >> n >> m; while(m--) { cin >> x >> y; t[x].id = x; t[x].son++; t[y].id = y; t[y].father = x; } sort(t + 1, t + n + 1, cmp); for(int i = 1; i <= n; i++) { if(t[i].father == 0) cout << t[i].id << " "; } cout << t[1].id; return 0; }