Submission #277131

# Submission time Handle Problem Language Result Execution time Memory
277131 2020-08-21T04:00:51 Z Bill_00 Traffic (IOI10_traffic) C++14
0 / 100
67 ms 63864 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];
int b[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]);
		}
	}
}
long long calc(int j){
	sum[j]=(long long)b[j];
	for(int i=0;i<adj[j].size();i++){
		if(adj[j][i]!=p[j]){
			sum[j]+=calc(adj[j][i]);
		}
	}
	return sum[j];
}
void check(int j){
	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];
			vis[adj[j][i]]=1;
			check(adj[j][i]);
		}
	}
	if(j!=0){
		dp[p[j]]=dp[j]+2*sum[j]-sum[0];
		check(p[j]);
	}
}
int LocateCentre(int n,int a[],int s[],int d[]){
	for(int i=0;i<n;i++){
		b[i]=a[i];
	}
	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);
	dp[leaf[0]]=0;
	vis[leaf[0]]=1;
	long long ans=2e9,id;
	check(leaf[0]);
	for(int i=0;i<n;i++){
		//cout << dp[i] << endl;
		if(dp[i]<ans){
			id=i;
			ans=dp[i];
		}	
	}
	return id;
}

Compilation message

traffic.cpp: In function 'void dfs(int)':
traffic.cpp:15:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for(int i=0;i<adj[j].size();i++){
      |              ~^~~~~~~~~~~~~~
traffic.cpp: In function 'long long int calc(int)':
traffic.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i=0;i<adj[j].size();i++){
      |              ~^~~~~~~~~~~~~~
traffic.cpp: In function 'void check(int)':
traffic.cpp:32:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i=0;i<adj[j].size();i++){
      |              ~^~~~~~~~~~~~~~
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:67:9: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |  return id;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 31616 KB Output is correct
2 Correct 21 ms 31616 KB Output is correct
3 Correct 21 ms 31608 KB Output is correct
4 Correct 21 ms 31616 KB Output is correct
5 Correct 21 ms 31688 KB Output is correct
6 Correct 22 ms 31616 KB Output is correct
7 Correct 21 ms 31636 KB Output is correct
8 Correct 24 ms 31616 KB Output is correct
9 Correct 22 ms 31628 KB Output is correct
10 Correct 22 ms 31616 KB Output is correct
11 Correct 22 ms 31616 KB Output is correct
12 Correct 25 ms 31744 KB Output is correct
13 Correct 22 ms 31736 KB Output is correct
14 Correct 22 ms 31744 KB Output is correct
15 Correct 21 ms 31616 KB Output is correct
16 Correct 23 ms 31744 KB Output is correct
17 Correct 23 ms 31616 KB Output is correct
18 Correct 21 ms 31744 KB Output is correct
19 Correct 22 ms 31616 KB Output is correct
20 Correct 23 ms 31616 KB Output is correct
21 Correct 21 ms 31616 KB Output is correct
22 Correct 23 ms 31744 KB Output is correct
23 Correct 22 ms 31744 KB Output is correct
24 Correct 22 ms 31744 KB Output is correct
25 Correct 24 ms 31736 KB Output is correct
26 Correct 22 ms 31744 KB Output is correct
27 Correct 22 ms 31744 KB Output is correct
28 Correct 22 ms 31744 KB Output is correct
29 Correct 26 ms 31744 KB Output is correct
30 Correct 23 ms 31744 KB Output is correct
31 Correct 26 ms 31744 KB Output is correct
32 Correct 23 ms 31700 KB Output is correct
33 Correct 23 ms 31744 KB Output is correct
34 Correct 21 ms 31616 KB Output is correct
35 Correct 27 ms 31744 KB Output is correct
36 Correct 24 ms 31744 KB Output is correct
37 Correct 33 ms 31736 KB Output is correct
38 Correct 29 ms 31744 KB Output is correct
39 Correct 27 ms 31724 KB Output is correct
40 Correct 23 ms 31744 KB Output is correct
41 Correct 24 ms 31744 KB Output is correct
42 Correct 27 ms 31792 KB Output is correct
43 Runtime error 67 ms 63864 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 31616 KB Output is correct
2 Correct 21 ms 31616 KB Output is correct
3 Correct 21 ms 31608 KB Output is correct
4 Correct 21 ms 31616 KB Output is correct
5 Correct 21 ms 31688 KB Output is correct
6 Correct 22 ms 31616 KB Output is correct
7 Correct 21 ms 31636 KB Output is correct
8 Correct 24 ms 31616 KB Output is correct
9 Correct 22 ms 31628 KB Output is correct
10 Correct 22 ms 31616 KB Output is correct
11 Correct 22 ms 31616 KB Output is correct
12 Correct 25 ms 31744 KB Output is correct
13 Correct 22 ms 31736 KB Output is correct
14 Correct 22 ms 31744 KB Output is correct
15 Correct 21 ms 31616 KB Output is correct
16 Correct 23 ms 31744 KB Output is correct
17 Correct 23 ms 31616 KB Output is correct
18 Correct 21 ms 31744 KB Output is correct
19 Correct 22 ms 31616 KB Output is correct
20 Correct 23 ms 31616 KB Output is correct
21 Correct 21 ms 31616 KB Output is correct
22 Correct 23 ms 31744 KB Output is correct
23 Correct 22 ms 31744 KB Output is correct
24 Correct 22 ms 31744 KB Output is correct
25 Correct 24 ms 31736 KB Output is correct
26 Correct 22 ms 31744 KB Output is correct
27 Correct 22 ms 31744 KB Output is correct
28 Correct 22 ms 31744 KB Output is correct
29 Correct 26 ms 31744 KB Output is correct
30 Correct 23 ms 31744 KB Output is correct
31 Correct 26 ms 31744 KB Output is correct
32 Correct 23 ms 31700 KB Output is correct
33 Correct 23 ms 31744 KB Output is correct
34 Correct 21 ms 31616 KB Output is correct
35 Correct 27 ms 31744 KB Output is correct
36 Correct 24 ms 31744 KB Output is correct
37 Correct 33 ms 31736 KB Output is correct
38 Correct 29 ms 31744 KB Output is correct
39 Correct 27 ms 31724 KB Output is correct
40 Correct 23 ms 31744 KB Output is correct
41 Correct 24 ms 31744 KB Output is correct
42 Correct 27 ms 31792 KB Output is correct
43 Runtime error 67 ms 63864 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 31616 KB Output is correct
2 Correct 21 ms 31616 KB Output is correct
3 Correct 21 ms 31608 KB Output is correct
4 Correct 21 ms 31616 KB Output is correct
5 Correct 21 ms 31688 KB Output is correct
6 Correct 22 ms 31616 KB Output is correct
7 Correct 21 ms 31636 KB Output is correct
8 Correct 24 ms 31616 KB Output is correct
9 Correct 22 ms 31628 KB Output is correct
10 Correct 22 ms 31616 KB Output is correct
11 Correct 22 ms 31616 KB Output is correct
12 Correct 25 ms 31744 KB Output is correct
13 Correct 22 ms 31736 KB Output is correct
14 Correct 22 ms 31744 KB Output is correct
15 Correct 21 ms 31616 KB Output is correct
16 Correct 23 ms 31744 KB Output is correct
17 Correct 23 ms 31616 KB Output is correct
18 Correct 21 ms 31744 KB Output is correct
19 Correct 22 ms 31616 KB Output is correct
20 Correct 23 ms 31616 KB Output is correct
21 Correct 21 ms 31616 KB Output is correct
22 Correct 23 ms 31744 KB Output is correct
23 Correct 22 ms 31744 KB Output is correct
24 Correct 22 ms 31744 KB Output is correct
25 Correct 24 ms 31736 KB Output is correct
26 Correct 22 ms 31744 KB Output is correct
27 Correct 22 ms 31744 KB Output is correct
28 Correct 22 ms 31744 KB Output is correct
29 Correct 26 ms 31744 KB Output is correct
30 Correct 23 ms 31744 KB Output is correct
31 Correct 26 ms 31744 KB Output is correct
32 Correct 23 ms 31700 KB Output is correct
33 Correct 23 ms 31744 KB Output is correct
34 Correct 21 ms 31616 KB Output is correct
35 Correct 27 ms 31744 KB Output is correct
36 Correct 24 ms 31744 KB Output is correct
37 Correct 33 ms 31736 KB Output is correct
38 Correct 29 ms 31744 KB Output is correct
39 Correct 27 ms 31724 KB Output is correct
40 Correct 23 ms 31744 KB Output is correct
41 Correct 24 ms 31744 KB Output is correct
42 Correct 27 ms 31792 KB Output is correct
43 Runtime error 67 ms 63864 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 31616 KB Output is correct
2 Correct 21 ms 31616 KB Output is correct
3 Correct 21 ms 31608 KB Output is correct
4 Correct 21 ms 31616 KB Output is correct
5 Correct 21 ms 31688 KB Output is correct
6 Correct 22 ms 31616 KB Output is correct
7 Correct 21 ms 31636 KB Output is correct
8 Correct 24 ms 31616 KB Output is correct
9 Correct 22 ms 31628 KB Output is correct
10 Correct 22 ms 31616 KB Output is correct
11 Correct 22 ms 31616 KB Output is correct
12 Correct 25 ms 31744 KB Output is correct
13 Correct 22 ms 31736 KB Output is correct
14 Correct 22 ms 31744 KB Output is correct
15 Correct 21 ms 31616 KB Output is correct
16 Correct 23 ms 31744 KB Output is correct
17 Correct 23 ms 31616 KB Output is correct
18 Correct 21 ms 31744 KB Output is correct
19 Correct 22 ms 31616 KB Output is correct
20 Correct 23 ms 31616 KB Output is correct
21 Correct 21 ms 31616 KB Output is correct
22 Correct 23 ms 31744 KB Output is correct
23 Correct 22 ms 31744 KB Output is correct
24 Correct 22 ms 31744 KB Output is correct
25 Correct 24 ms 31736 KB Output is correct
26 Correct 22 ms 31744 KB Output is correct
27 Correct 22 ms 31744 KB Output is correct
28 Correct 22 ms 31744 KB Output is correct
29 Correct 26 ms 31744 KB Output is correct
30 Correct 23 ms 31744 KB Output is correct
31 Correct 26 ms 31744 KB Output is correct
32 Correct 23 ms 31700 KB Output is correct
33 Correct 23 ms 31744 KB Output is correct
34 Correct 21 ms 31616 KB Output is correct
35 Correct 27 ms 31744 KB Output is correct
36 Correct 24 ms 31744 KB Output is correct
37 Correct 33 ms 31736 KB Output is correct
38 Correct 29 ms 31744 KB Output is correct
39 Correct 27 ms 31724 KB Output is correct
40 Correct 23 ms 31744 KB Output is correct
41 Correct 24 ms 31744 KB Output is correct
42 Correct 27 ms 31792 KB Output is correct
43 Runtime error 67 ms 63864 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -