提交时间:2024-01-22 17:20:16
运行 ID: 123129
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int n,m,tree[10010]; int x,y,root,maxn,sum = 0,maxx = 0; cin >> n >> m; for(int i = 1;i <=m;i++){ cin >> x >> y; tree[y] = x; } for(int i = 1;i <=n;i++){ if(tree[i] == 0){ root = i; break; } } for(int i = 1;i <= n;i++){ sum = 0; for(int j = 1;j <= n;j++){ if(tree[j] == i) sum++; } if(sum > maxx) maxx = sum;maxn = i; } cout << root << ' '<< maxn/4; return 0; }