This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----
#include "traffic.h"
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define mod 1000000007
#define inf (int)1e18
const int mxn = 1e6+10;
vector<int> g[mxn];
int people[mxn];
int dp[mxn];
int children[mxn];
int total;
void dfs(int v, int p=-1){
for(int u : g[v]){
if(u==p) continue;
dfs(u,v);
children[v] += children[u];
dp[v] = max(dp[v],children[u]);
}
dp[v] = max(dp[v],total-children[v]-people[v]);
children[v] += people[v];
}
int LocateCentre (int n, int p[], int d[], int s[]){
for(int i=0;i<n;i++) people[i] = p[i],total += p[i];
for(int i=0;i<n-1;i++){
g[s[i]].push_back(d[i]);
g[d[i]].push_back(s[i]);
}
int mn = inf,idx=-1;
for(int i=0;i<n;i++){
if(mn>dp[i]){
mn = dp[i];
idx = i;
}
}
return idx;
}
// int32_t main(){
// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int n; cin >> n;
// for(int i=0;i<n;i++) cin >> people[i], total+=people[i], dp[i] = INT_MIN;
// for(int i=0;i<n-1;i++){
// int u,v; cin >> u >> v;
// g[v].push_back(u);
// g[u].push_back(v);
// }
// dfs(0);
// for(int i=0;i<n;i++){
// }
// return 0;
// }
# | 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... |