Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
125174 | 宋春霖 | 树根和宝藏 | C++ | 通过 | 100 | 0 MS | 252 KB | 519 | 2024-01-23 16:31:17 |
#include<bits/stdc++.h> using namespace std; int n, m, tree[1005]; int main(){ int root, maxr, sum = 0, maxx = 0; cin >> n >> m; for (int i = 1; i <= m; i++){ int x, y; 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; maxr = i; } } cout << root << " " << maxr << endl; }