# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
662556 | esomer | Traffic (IOI10_traffic) | C++17 | 0 ms | 0 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"
#include "grader.h"
using namespace std;
#define ll long long
#define endl "\n"
const int MOD = 998244353;
int mn, city, total;
int DFS(int x, vector<int>& v, vector<vector<int>>& adj, int p){
int subtree = 0;
int mx = 0;
for(int node : adj[x]){
if(node == p) continue;
int sz = DFS(node, v, adj, x);
mx = max(mx, sz);
subtree += sz;
}
mx = max(mx, total - sz - v[x]);
if(mx < mn){
mn = mx;
city = x;
}
return subtree + v[x];
}
int LocateCentre(int n, int* P, int* S, int* D){
vector<int> v(n);
vector<vector<int>> adj(n);
total = 0;
for(int i = 0; i < n; i++) {v[i] = P[i]; total += v[i];}
for(int i = 0; i < n - 1; i++){
adj[S[i]].push_back(D[i]);
adj[D[i]].push_back(S[i]);
}
mn = 2e9;
DFS(0, v, adj, -1);
return city;
}