Submission #730177

#TimeUsernameProblemLanguageResultExecution timeMemory
730177lucriTraffic (IOI10_traffic)C++17
Compilation error
0 ms0 KiB
//#include "traffic.h" #include <bits/stdc++.h> #include <stdio.h> static int N,P[1000000],S[1000000],D[1000000]; std::vector<std::vector<int>>a; int v[1000010],nr[1000010]; void parcurge(int nod,int ant) { for(auto x:a[nod]) { if(x!=ant) { parcurge(x,nod); v[nod]+=v[x]; } } v[nod]+=nr[nod]; } int LocateCentre(int N, int pp[], int S[], int D[]) { int n=N,ans,vans=2000000000,sf,fmax,vmax,rad; a.resize(n+5); for(int i=0;i<n-1;++i) { nr[i]=pp[i]; a[S[i]].push_back(D[i]); a[D[i]].push_back(S[i]); } nr[n-1]=pp[n-1]; parcurge(n/2,-1); ans=n/2; rad=n/2; do { sf=0; vmax=0; for(auto x:a[rad]) { sf+=v[x]; if(v[x]>vmax) { vmax=v[x]; fmax=x; } } if(vmax<vans) { vans=vmax; ans=rad; } v[fmax]=v[rad]; v[rad]=sf-vmax+nr[rad]; rad=fmax; }while(fmax!=ans); return ans; } int main(){ int i; scanf("%d",&N); for (i=0;i<N;i++) scanf("%d",&P[i]); for (i=0;i<N-1;i++) scanf("%d%d",&S[i],&D[i]); int r = LocateCentre(N,P,S,D); printf("%d\n",r); return 0; }

Compilation message (stderr)

traffic.cpp: In function 'int main()':
traffic.cpp:62:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |    scanf("%d",&N);
      |    ~~~~~^~~~~~~~~
traffic.cpp:63:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |    for (i=0;i<N;i++) scanf("%d",&P[i]);
      |                      ~~~~~^~~~~~~~~~~~
traffic.cpp:64:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |    for (i=0;i<N-1;i++) scanf("%d%d",&S[i],&D[i]);
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:55:16: warning: 'fmax' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |     }while(fmax!=ans);
      |            ~~~~^~~~~
/usr/bin/ld: /tmp/ccewCAxp.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc6gp9Nm.o:traffic.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status