# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362285 | saifu | Traffic (IOI10_traffic) | C++14 | 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.
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----
#include<bits/stdc++.h>
#include "traffic.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define int long long
#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];
void dfs(int v, int p=-1){
dp[v] = people[v];
for(int u : g[v]){
if(u==p) continue;
dfs(u,v);
dp[v] += dp[u];
}
}
int LocateCentre(int n, int p[], int d[], int s[]){
for(int i=0;i<n;i++) people[i] = 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;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) dp[i] = 0;
dfs(i);
int mx = 0;
for(int u : g[i]){
mx = max(mx,dp[u]);
}
mn = min(mn,mx);
}
return mn;
}
// 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];
// for(int i=0;i<n-1;i++){
// int u,v; cin >> u >> v;
// g[v].push_back(u);
// g[u].push_back(v);
// }
// return 0;
// }