This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "traffic.h"
#include <bits/stdc++.h>
std::vector<std::vector<int>>a;
int v[1000010];
void parcurge(int nod,int ant,int pp[])
{
for(auto x:a[nod])
{
if(x!=ant)
{
parcurge(x,nod,pp);
v[nod]+=v[x];
}
}
v[nod]+=pp[nod];
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
int n=N,ans=1,vans=2000000000,sf,fmax,vmax,rad=1;
a.resize(n+5);
for(int i=1;i<n;++i)
{
a[S[i]].push_back(D[i]);
a[D[i]].push_back(S[i]);
}
parcurge(1,0,pp);
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[rad]=sf-vmax+v[rad];
rad=fmax;
}while(fmax!=ans);
return ans;
}
Compilation message (stderr)
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:46:16: warning: 'fmax' may be used uninitialized in this function [-Wmaybe-uninitialized]
46 | }while(fmax!=ans);
| ~~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |