답안 #312171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312171 2020-10-12T14:45:01 Z AmineTrabelsi Traffic (IOI10_traffic) C++14
0 / 100
16 ms 23808 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pb push_back 
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

// Hi
const int M = 1e6;
vector<int> gr[M];
int *people;
ll sum[M];
int from[M];
void dfs(int i,int par){
	sum[i] = people[i];
	for(auto u:gr[i]){
		if(u!=par){
			from[u]=i;
			dfs(u,i);
			sum[i]+=sum[u];
		}
	}
}/*
ll df(int i,int par){
	ll res = people[i];
	for(auto u:gr[i]){
		if(u != par){
			res += df(u,i);
		}
	}
	return res;
}*/
ll LocateCentre(int n,int p[],int ff[],int d[]){
	for(int i=0;i<n-1;i++){
		gr[ff[i]].pb(d[i]);
		gr[d[i]].pb(ff[i]);
	}
	people = p;
	dfs(0,0);
	ll res = 1e18;
	int city = 0;
	for(int i=0;i<n;i++){
		ll x = 0;
		//cout<<i<<" ";
		for(auto e:gr[i]){
			if(i == from[e]){
				//cout<<sum[e]-p[e]<<' ';
				x = max(x,sum[e]-p[e]);
			}else //cout<<sum[0]-sum[i]<<" ",
				x = max(x,sum[0]-sum[i]);
		}
		if(x < res){
			city = i;
			res = x;
		}
		//cout<<'\n';
	}
	return city;
}
/*
int main(){
	int p[6] = {10,10,10,10,10,10},s[5] = {1,2,3,4,0},d[5] = {5,1,2,1,4};
	cout<<LocateCentre(6,p,s,d)<<'\n';
	return 0;
}
*/

# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -