# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550164 | AJ00 | Traffic (IOI10_traffic) | C++14 | 951 ms | 186364 KiB |
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"
using namespace std;
const int MAXN = 1000001;
long long int s[MAXN],pp[MAXN],maxm[MAXN];
int n;
vector<int> adj[MAXN];
void dfs(int x, int p = 1){
s[x] = maxm[x] = 0;
for (int c: adj[x]){
if (c != p){
// cout << c << "\n";
dfs(c,x);
maxm[x] = max(maxm[x],pp[c]+s[c]);
s[x] += pp[c]+s[c];
}
}
// cout << x << " " << s[x] << "\n";
}
int LocateCentre(int N, int P[], int S[], int D[]){
n = N;
int ans;
for (int i = 0; i < n-1; i++){
S[i]++;
D[i]++;
//cout << S[i] << " " << D[i] << "\n";
adj[S[i]].push_back(D[i]);
adj[D[i]].push_back(S[i]);
pp[i+1] = P[i];
}
pp[n] = P[n-1];
dfs(1);
long long int cur = 1e18;
for (int i = 1; i <= n; i++){
if (cur > max(s[1]+pp[1]-s[i]-pp[i],maxm[i])){
ans = i;
cur = max(s[1]+pp[1]-s[i]-pp[i],maxm[i]);
}
}
ans--;
return ans;
}
Compilation message (stderr)
# | 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... |