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 int
using namespace std;
vector<vector<int>> adj(1000000,vector<int>());
map<pair<int,int>,ll> m;
ll dp(int p,int c,int* P){
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,P);
}
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]);
}
ll ans = INT_MAX;
int index = -1;
for(int i=0;i<n;i++){
ll local = INT_MIN;
for(int v:adj[i])local = max(local,dp(i,v,p));
if(local<ans){
ans = local;
index = i;
}
}
return index;
}
# | 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... |