Submission #277089

# Submission time Handle Problem Language Result Execution time Memory
277089 2020-08-21T02:57:41 Z Bill_00 Traffic (IOI10_traffic) C++14
Compilation error
0 ms 0 KB
#include <traffic.h>
#include <bits/stdc++.h>
using namespace std;
vector<long long>adj[1000000];
vector<long long>leaf;
long long p[1000000];
long long sum[1000000];
long long dp[1000000],vis[1000000];
void dfs(int j){
	if(adj[j].size()==1 && p[j]==adj[j][0]){
		leaf.push_back(j);
		return;
	}
	for(int i=0;i<adj[j].size();i++){
		if(adj[j][i]!=p[j]){
			p[adj[j][i]]=j;
			dfs(adj[j][i]);
		}
	}
}
void check(int j){
	vis[j]=1;
	for(int i=0;i<adj[j].size();i++){
		if(vis[adj[j][i]]==0 && adj[j][i]!=p[j]){
			dp[adj[j][i]]=dp[j]-(2*sum[adj[j][i]])+sum[0];
			check(adj[j][i]);
		}
	}
	if(j!=0){
		dp[p[j]]=dp[j]+2*sum[j]-sum[0];
		check(p[j]);
	}
}
long long calc(long long j,long long a[]){
	sum[j]=a[j];
	for(int i=0;i<adj[j].size();i++){
		if(adj[j][i]!=p[j]){
			sum[j]+=calc(adj[j][i],a);
		}
	}
	return sum[j];
}
int LocateCentre(long long n,long long a[],long long s[],long long d[]){
	memset(vis,0,sizeof(vis));
	for(int i=0;i<n-1;i++){
		adj[s[i]].push_back(d[i]);
		adj[d[i]].push_back(s[i]);
	}
	p[0]=-1;
	dfs(0);
	calc(0,a);
	dp[leaf[0]]=0;
	int ans=0,id=0;
	check(leaf[0]);
	for(int i=1;i<n;i++){
		if(dp[i]<ans){
			id=i;
			ans=dp[i];
		}	
	}
	return id;
}

Compilation message

traffic.cpp: In function 'void dfs(int)':
traffic.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=0;i<adj[j].size();i++){
      |              ~^~~~~~~~~~~~~~
traffic.cpp: In function 'void check(int)':
traffic.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i=0;i<adj[j].size();i++){
      |              ~^~~~~~~~~~~~~~
traffic.cpp: In function 'long long int calc(long long int, long long int*)':
traffic.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i=0;i<adj[j].size();i++){
      |              ~^~~~~~~~~~~~~~
/tmp/ccAhIdyS.o: In function `main':
grader.cpp:(.text.startup+0xad): undefined reference to `LocateCentre(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status