# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
532227 | srivatsav_kannan | 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.
#include <iostream>
#include "traffic.h"
#include <fstream>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <numeric>
#include <stack>
#include <cstring>
#include <bitset>
#include <climits>
#include <valarray>
#include <list>
#define INF 1000000000
#define endl '\n'
#define int long long
#define mod 1000000007
using namespace std;
vector<int> adj[1000];
int vis[1000], ar[1000];
int dfs(int node, bool root = true){
int mx = 0;
if (!root) mx = ar[node];
vis[node] = 1;
for (int child:adj[node]){
if (vis[child] == 0){
int cur = dfs(child, false);
if (root) mx = max(mx, cur);
else mx += cur;
}
}
return mx;
}
int LocateCentre(int n, int p[], int s[], int d[]){
for (int i = 0; i < n-1; i++){
adj[s[i]].push_back(d[i]);
adj[d[i]].push_back(s[i]);
}
for (int i = 0; i < n; i++) ar[i] = p[i];
int mn = 1e17, mni = -1;
for (int i = 0; i < n; i++){
memset(vis, 0, sizeof vis);
int cur = dfs(i);
if (cur < mn){
mn = cur;
mni = i;
}
}
return mni;
}