56012023-08-02 13:45:01TomaSajtLegtöbb unoka (80 pont)cpp17Accepted 80/804ms6028 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n, m;
  cin >> n >> m;

  vector<int> parent(n + 1, -1);

  for (int i = 0; i < m; i++) {
    int par, self;
    cin >> par >> self;
    parent[self] = par;
  }

  vector<int> child_count(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    if (parent[i] == -1) continue;
    child_count[parent[i]] += 1;
  }

  vector<int> grandchild_count(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    if (parent[i] == -1) continue;
    grandchild_count[parent[i]] += child_count[i];
  }

  auto best_it = max_element(grandchild_count.begin(), grandchild_count.end());

  if (*best_it == 0) {
    cout << "-1";
  }
  else {
    cout << best_it - grandchild_count.begin() << ' ' << *best_it;
  }
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/03ms1960 KiB
2Accepted0/04ms2280 KiB
3Accepted4/42ms2316 KiB
4Accepted4/43ms2428 KiB
5Accepted4/44ms2904 KiB
6Accepted4/44ms3280 KiB
7Accepted4/43ms3536 KiB
8Accepted4/42ms3460 KiB
9Accepted4/44ms3776 KiB
10Accepted4/44ms4072 KiB
11Accepted4/44ms4124 KiB
12Accepted4/44ms4168 KiB
13Accepted4/44ms4648 KiB
14Accepted4/44ms4592 KiB
15Accepted4/44ms4964 KiB
16Accepted4/44ms5228 KiB
17Accepted4/44ms5512 KiB
18Accepted4/44ms6024 KiB
19Accepted2/23ms5824 KiB
20Accepted2/23ms5888 KiB
21Accepted3/33ms5888 KiB
22Accepted3/33ms5900 KiB
23Accepted3/34ms5940 KiB
24Accepted3/34ms6028 KiB