Submission #363247

#TimeUsernameProblemLanguageResultExecution timeMemory
363247vm152Traffic (IOI10_traffic)C++17
50 / 100
671 ms248172 KiB
#include <bits/stdc++.h> using namespace std ; #define ios ios_base::sync_with_stdio(0); cin.tie(0) ; cout.tie(0) #define eb emplace_back #define mp make_pair #define f first #define s second #define endl '\n' typedef long long int ll ; const int MAX = 1e6 ; vector<int> tree[MAX + 5] ; vector<int> cnt[MAX + 5] ; ll sum = 0 ; ll dfs(int node, int s, int p[]) { ll count = 0 ; for (int i : tree[node]) { if (i != s) { count = dfs(i, node, p) + p[i] ; cnt[node].eb(count) ; } } ll sm = 0 ; for (int i : cnt[node]) sm += i ; cnt[node].eb(sum - sm - p[node]) ; return count ; } int LocateCentre(int n, int p[], int s[], int d[]) { sum = 0 ; for (int i = 0 ; i < n ; i++) { sum += p[i] ; tree[i].clear() ; cnt[i].clear() ; } for (int i = 0; i < n - 1 ; i++) { tree[s[i]].eb(d[i]) ; tree[d[i]].eb(s[i]) ; } ll rand = dfs(0, -1, p) ; int index = 0 ; while (cnt[index].empty()) index++ ; sort(cnt[index].begin(), cnt[index].end()) ; reverse(cnt[index].begin(), cnt[index].end()) ; int start = index + 1 ; for (int i = start ; i < n ; i++) { if (!cnt[i].empty()) { sort(cnt[i].begin(), cnt[i].end()) ; reverse(cnt[i].begin(), cnt[i].end()) ; if (cnt[i][0] < cnt[index][0]) { index = i ; } else if (cnt[i][0] == cnt[index][0]) { int j = 1, k = 1 ; while (j < int(cnt[i].size()) && k < int(cnt[index].size()) && cnt[i][j] == cnt[index][k]) j++, k++ ; if (j >= int(cnt[i].size())) index = i ; else if (k < int(cnt[index].size()) && cnt[i][j] < cnt[index][k]) index = i ; } } } return index ; } /* int main(){ ios ; int n ; cin >> n ; int p[n] ; int s[n] ; int d[n] ; for (int i = 0 ; i < n ; i++) cin >> p[i] ; for (int i = 0 ; i < n - 1 ; i++) cin >> s[i] ; for (int i = 0 ; i < n - 1 ; i++) cin >> d[i] ; int ans = LocateCentre(n, p, s, d) ; cout << ans << endl ; } */

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:43:6: warning: unused variable 'rand' [-Wunused-variable]
   43 |   ll rand = dfs(0, -1, p) ;
      |      ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...