This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "traffic.h"
#define pb push_back
#define ll long long
using namespace std;
int P[1000000];
vector<vector<int>> adj(1000000,vector<int>());
map<pair<int,int>,ll> m;
ll dp(int p,int c){
if(m.find((pair<int,int>){p,c})!=m.end())return m[(pair<int,int>){p,c}];
ll ans = P[c];
for(int v:adj[c]){
if(v==p)continue;
ans += dp(c,v);
}
m.insert({{p,c},ans});
return ans;
}
int LocateCentre(int n,int p[],int s[],int d[]){
for(int i=0;i<n-1;i++){
adj.at(s[i]).pb(d[i]);
adj.at(d[i]).pb(s[i]);
}
for(int i=0;i<n;i++)P[i]=p[i];
ll ans = LLONG_MAX;
int index = -1;
for(int i=0;i<n;i++){
ll local = LLONG_MIN;
for(int v:adj[i])local = max(local,dp(i,v));
if(local<ans){
ans = local;
index = i;
}
}
cout << index << "\n";
}
Compilation message (stderr)
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:41:5: warning: no return statement in function returning non-void [-Wreturn-type]
41 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |