# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241613 | lakshith_ | 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 <bits/stdc++.h>
#include "traffic.h"
#include "grader.h"
#define pb push_back
using namespace std;
vector<vector<int>> adjList(1000,vector<int>());
int DFS(int n,int s,int* p){
int sum = p[n];
for(int x:adjList.at(n))
if(x!=s)sum += DFS(x,n,p);
return sum;
}
int LocateCenter(int n,int p[],int s[],int d[]){
for(int i=0;i<n-1;i++){
adjList.at(s[i]).pb(d[i]);
adjList.at(d[i]).pb(s[i]);
}
int MIN = INT_MAX;
int minPos = 0;
for(int i=0;i<n;i++){
int MAX = 0;
for(int x:adjList.at(i))
MAX = max(MAX,DFS(x,i,p));
if(MAX < MIN){
MIN = MAX;
minPos = i;
}
}
return minPos;
}