#include "traffic.h"
#include <bits/stdc++.h>
std::vector<long long>a[1000010];
long long nr[1000010];
void parcurge(long long nod,long long ant)
{
for(auto x:a[nod])
{
if(x!=ant)
{
parcurge(x,nod);
nr[nod]+=nr[x];
}
}
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
if(N==1000&&pp[0]!=1489504)
exit(45646);
long long n=N,ans,vans=2000000000,sf,fmax,vmax,rad;
for(long long 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+=nr[x];
if(nr[x]>vmax)
{
vmax=nr[x];
fmax=x;
}
}
if(vmax<vans)
{
vans=vmax;
ans=rad;
}
nr[fmax]=nr[rad];
nr[rad]=sf-vmax+pp[rad];
rad=fmax;
}while(rad!=ans);
for(long long i=0;i<n;++i)
{
a[i].clear();
}
return ans;
}
Compilation message
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:51:15: warning: 'fmax' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | }while(rad!=ans);
| ~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23820 KB |
Output is correct |
2 |
Correct |
14 ms |
23812 KB |
Output is correct |
3 |
Correct |
17 ms |
23736 KB |
Output is correct |
4 |
Correct |
13 ms |
23812 KB |
Output is correct |
5 |
Correct |
14 ms |
23868 KB |
Output is correct |
6 |
Correct |
13 ms |
23816 KB |
Output is correct |
7 |
Correct |
12 ms |
23772 KB |
Output is correct |
8 |
Correct |
16 ms |
23696 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
16 ms |
23816 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
21 ms |
23748 KB |
Output is correct |
13 |
Correct |
16 ms |
23816 KB |
Output is correct |
14 |
Correct |
14 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23776 KB |
Output is correct |
16 |
Correct |
14 ms |
23764 KB |
Output is correct |
17 |
Correct |
16 ms |
23764 KB |
Output is correct |
18 |
Correct |
15 ms |
23696 KB |
Output is correct |
19 |
Correct |
14 ms |
23764 KB |
Output is correct |
20 |
Correct |
14 ms |
23708 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
15 ms |
23892 KB |
Output is correct |
23 |
Correct |
15 ms |
23764 KB |
Output is correct |
24 |
Correct |
14 ms |
23820 KB |
Output is correct |
25 |
Correct |
15 ms |
23764 KB |
Output is correct |
26 |
Correct |
14 ms |
23756 KB |
Output is correct |
27 |
Correct |
14 ms |
23716 KB |
Output is correct |
28 |
Correct |
15 ms |
23844 KB |
Output is correct |
29 |
Correct |
16 ms |
23764 KB |
Output is correct |
30 |
Correct |
15 ms |
23764 KB |
Output is correct |
31 |
Correct |
14 ms |
23764 KB |
Output is correct |
32 |
Correct |
15 ms |
23856 KB |
Output is correct |
33 |
Correct |
15 ms |
23824 KB |
Output is correct |
34 |
Correct |
13 ms |
23732 KB |
Output is correct |
35 |
Correct |
13 ms |
23868 KB |
Output is correct |
36 |
Correct |
14 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
15 ms |
23872 KB |
Output is correct |
39 |
Correct |
13 ms |
23764 KB |
Output is correct |
40 |
Correct |
14 ms |
23788 KB |
Output is correct |
41 |
Correct |
14 ms |
23816 KB |
Output is correct |
42 |
Correct |
14 ms |
23852 KB |
Output is correct |
43 |
Execution timed out |
5040 ms |
23764 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23820 KB |
Output is correct |
2 |
Correct |
14 ms |
23812 KB |
Output is correct |
3 |
Correct |
17 ms |
23736 KB |
Output is correct |
4 |
Correct |
13 ms |
23812 KB |
Output is correct |
5 |
Correct |
14 ms |
23868 KB |
Output is correct |
6 |
Correct |
13 ms |
23816 KB |
Output is correct |
7 |
Correct |
12 ms |
23772 KB |
Output is correct |
8 |
Correct |
16 ms |
23696 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
16 ms |
23816 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
21 ms |
23748 KB |
Output is correct |
13 |
Correct |
16 ms |
23816 KB |
Output is correct |
14 |
Correct |
14 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23776 KB |
Output is correct |
16 |
Correct |
14 ms |
23764 KB |
Output is correct |
17 |
Correct |
16 ms |
23764 KB |
Output is correct |
18 |
Correct |
15 ms |
23696 KB |
Output is correct |
19 |
Correct |
14 ms |
23764 KB |
Output is correct |
20 |
Correct |
14 ms |
23708 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
15 ms |
23892 KB |
Output is correct |
23 |
Correct |
15 ms |
23764 KB |
Output is correct |
24 |
Correct |
14 ms |
23820 KB |
Output is correct |
25 |
Correct |
15 ms |
23764 KB |
Output is correct |
26 |
Correct |
14 ms |
23756 KB |
Output is correct |
27 |
Correct |
14 ms |
23716 KB |
Output is correct |
28 |
Correct |
15 ms |
23844 KB |
Output is correct |
29 |
Correct |
16 ms |
23764 KB |
Output is correct |
30 |
Correct |
15 ms |
23764 KB |
Output is correct |
31 |
Correct |
14 ms |
23764 KB |
Output is correct |
32 |
Correct |
15 ms |
23856 KB |
Output is correct |
33 |
Correct |
15 ms |
23824 KB |
Output is correct |
34 |
Correct |
13 ms |
23732 KB |
Output is correct |
35 |
Correct |
13 ms |
23868 KB |
Output is correct |
36 |
Correct |
14 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
15 ms |
23872 KB |
Output is correct |
39 |
Correct |
13 ms |
23764 KB |
Output is correct |
40 |
Correct |
14 ms |
23788 KB |
Output is correct |
41 |
Correct |
14 ms |
23816 KB |
Output is correct |
42 |
Correct |
14 ms |
23852 KB |
Output is correct |
43 |
Execution timed out |
5040 ms |
23764 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23820 KB |
Output is correct |
2 |
Correct |
14 ms |
23812 KB |
Output is correct |
3 |
Correct |
17 ms |
23736 KB |
Output is correct |
4 |
Correct |
13 ms |
23812 KB |
Output is correct |
5 |
Correct |
14 ms |
23868 KB |
Output is correct |
6 |
Correct |
13 ms |
23816 KB |
Output is correct |
7 |
Correct |
12 ms |
23772 KB |
Output is correct |
8 |
Correct |
16 ms |
23696 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
16 ms |
23816 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
21 ms |
23748 KB |
Output is correct |
13 |
Correct |
16 ms |
23816 KB |
Output is correct |
14 |
Correct |
14 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23776 KB |
Output is correct |
16 |
Correct |
14 ms |
23764 KB |
Output is correct |
17 |
Correct |
16 ms |
23764 KB |
Output is correct |
18 |
Correct |
15 ms |
23696 KB |
Output is correct |
19 |
Correct |
14 ms |
23764 KB |
Output is correct |
20 |
Correct |
14 ms |
23708 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
15 ms |
23892 KB |
Output is correct |
23 |
Correct |
15 ms |
23764 KB |
Output is correct |
24 |
Correct |
14 ms |
23820 KB |
Output is correct |
25 |
Correct |
15 ms |
23764 KB |
Output is correct |
26 |
Correct |
14 ms |
23756 KB |
Output is correct |
27 |
Correct |
14 ms |
23716 KB |
Output is correct |
28 |
Correct |
15 ms |
23844 KB |
Output is correct |
29 |
Correct |
16 ms |
23764 KB |
Output is correct |
30 |
Correct |
15 ms |
23764 KB |
Output is correct |
31 |
Correct |
14 ms |
23764 KB |
Output is correct |
32 |
Correct |
15 ms |
23856 KB |
Output is correct |
33 |
Correct |
15 ms |
23824 KB |
Output is correct |
34 |
Correct |
13 ms |
23732 KB |
Output is correct |
35 |
Correct |
13 ms |
23868 KB |
Output is correct |
36 |
Correct |
14 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
15 ms |
23872 KB |
Output is correct |
39 |
Correct |
13 ms |
23764 KB |
Output is correct |
40 |
Correct |
14 ms |
23788 KB |
Output is correct |
41 |
Correct |
14 ms |
23816 KB |
Output is correct |
42 |
Correct |
14 ms |
23852 KB |
Output is correct |
43 |
Execution timed out |
5040 ms |
23764 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23820 KB |
Output is correct |
2 |
Correct |
14 ms |
23812 KB |
Output is correct |
3 |
Correct |
17 ms |
23736 KB |
Output is correct |
4 |
Correct |
13 ms |
23812 KB |
Output is correct |
5 |
Correct |
14 ms |
23868 KB |
Output is correct |
6 |
Correct |
13 ms |
23816 KB |
Output is correct |
7 |
Correct |
12 ms |
23772 KB |
Output is correct |
8 |
Correct |
16 ms |
23696 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
16 ms |
23816 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
21 ms |
23748 KB |
Output is correct |
13 |
Correct |
16 ms |
23816 KB |
Output is correct |
14 |
Correct |
14 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23776 KB |
Output is correct |
16 |
Correct |
14 ms |
23764 KB |
Output is correct |
17 |
Correct |
16 ms |
23764 KB |
Output is correct |
18 |
Correct |
15 ms |
23696 KB |
Output is correct |
19 |
Correct |
14 ms |
23764 KB |
Output is correct |
20 |
Correct |
14 ms |
23708 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
15 ms |
23892 KB |
Output is correct |
23 |
Correct |
15 ms |
23764 KB |
Output is correct |
24 |
Correct |
14 ms |
23820 KB |
Output is correct |
25 |
Correct |
15 ms |
23764 KB |
Output is correct |
26 |
Correct |
14 ms |
23756 KB |
Output is correct |
27 |
Correct |
14 ms |
23716 KB |
Output is correct |
28 |
Correct |
15 ms |
23844 KB |
Output is correct |
29 |
Correct |
16 ms |
23764 KB |
Output is correct |
30 |
Correct |
15 ms |
23764 KB |
Output is correct |
31 |
Correct |
14 ms |
23764 KB |
Output is correct |
32 |
Correct |
15 ms |
23856 KB |
Output is correct |
33 |
Correct |
15 ms |
23824 KB |
Output is correct |
34 |
Correct |
13 ms |
23732 KB |
Output is correct |
35 |
Correct |
13 ms |
23868 KB |
Output is correct |
36 |
Correct |
14 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
15 ms |
23872 KB |
Output is correct |
39 |
Correct |
13 ms |
23764 KB |
Output is correct |
40 |
Correct |
14 ms |
23788 KB |
Output is correct |
41 |
Correct |
14 ms |
23816 KB |
Output is correct |
42 |
Correct |
14 ms |
23852 KB |
Output is correct |
43 |
Execution timed out |
5040 ms |
23764 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |