Submission #287873

#TimeUsernameProblemLanguageResultExecution timeMemory
287873Bill_00Traffic (IOI10_traffic)C++14
0 / 100
63 ms63864 KiB
#include <traffic.h> #include <bits/stdc++.h> using namespace std; vector<long long>adj[1000001]; vector<long long>leaf; long long p[1000001]; long long sum[1000001]; long long dp[1000001],vis[1000001]; int b[1000001]; 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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...