#include<bits/stdc++.h>
#include "traffic.h"
#define ll long long int
#define pb push_back
#define mp make_pair
#define FOR(i,n) for(i=0;i<(n);++i)
#define FORe(i,n) for(i=1;i<=(n);++i)
#define FORr(i,a,b) for(i=(a);i<(b);++i)
#define FORrev(i,n) for(i=(n);i>=0;--i)
#define F0R(i,n) for(int i=0;i<(n);++i)
#define F0Re(i,n) for(int i=1;i<=(n);++i)
#define F0Rr(i,a,b) for(ll i=(a);i<(b);++i)
#define F0Rrev(i,n) for(int i=(n);i>=0;--i)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first
#define ss second
#define cd complex<double>
#define vcd vector<cd>
#define ldd long double
#define dbgLine cout<<"Line : "<<__LINE__<<'\n'
#define all(x) (x).begin(),(x).end()
using namespace std;
/*
const short int __PRECISION = 10;
const ll MOD = 1e9+7;
const ll INF = 1e17 + 1101;
const ll LOGN = 17;
const ll MAXN = 1e6+5;
const ll ROOTN = 320;
const ldd PI = acos(-1);
const ldd EPS = 1e-7;*/
#define MAXN 1000006
#define INF 100000000000000017
vector<ll> g[MAXN];
ll People[MAXN], dp[MAXN], sum[MAXN], sm;
ll dfs(ll a, ll par)
{
dp[a] = 0;
sum[a] = People[a];
for(ll b : g[a])
if(b != par)
dp[a] = max(dp[a], dfs(b, a)), sum[a] += sum[b];
return dp[a] + People[a];
}
int LocateCentre(int N, int* P, int* S, int* D)
{
sm = 0;
F0R(i, N)
g[i].clear(), People[i] = P[i], sm += P[i];
F0R(i, N-1)
{
g[S[i]].pb(D[i]);
g[D[i]].pb(S[i]);
}
dfs(1, -1);
ii mx = mp(INF, -1);
F0R(i, N)
mx = min(mx, mp(max(dp[i],sm - sum[i]),(ll) i));
//cerr<<mx.ff<<' '<<mx.ss<<'\n';
assert(mx.ss < INT_MAX);
return mx.ss;
}
/*
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin>>N;
int P[N], S[N], D[N];
F0R(i, N)
cin>>P[i];
F0R(i, N-1)
cin>>S[i]>>D[i];
cout<<LocateCenter(N, P, S, D);
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
20 ms |
23936 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
18 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
18 ms |
23936 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
18 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
18 ms |
23936 KB |
Output is correct |
15 |
Correct |
18 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
18 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23928 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
22 ms |
23856 KB |
Output is correct |
22 |
Correct |
18 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
19 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23936 KB |
Output is correct |
26 |
Correct |
19 ms |
23808 KB |
Output is correct |
27 |
Correct |
19 ms |
23936 KB |
Output is correct |
28 |
Correct |
18 ms |
23936 KB |
Output is correct |
29 |
Correct |
18 ms |
23936 KB |
Output is correct |
30 |
Correct |
19 ms |
23936 KB |
Output is correct |
31 |
Correct |
18 ms |
23936 KB |
Output is correct |
32 |
Correct |
19 ms |
23936 KB |
Output is correct |
33 |
Correct |
20 ms |
24064 KB |
Output is correct |
34 |
Correct |
18 ms |
23808 KB |
Output is correct |
35 |
Correct |
19 ms |
23936 KB |
Output is correct |
36 |
Correct |
18 ms |
23936 KB |
Output is correct |
37 |
Correct |
20 ms |
23936 KB |
Output is correct |
38 |
Correct |
19 ms |
23936 KB |
Output is correct |
39 |
Correct |
19 ms |
23936 KB |
Output is correct |
40 |
Correct |
19 ms |
23936 KB |
Output is correct |
41 |
Correct |
19 ms |
23936 KB |
Output is correct |
42 |
Correct |
19 ms |
23936 KB |
Output is correct |
43 |
Correct |
19 ms |
23936 KB |
Output is correct |
44 |
Correct |
18 ms |
23808 KB |
Output is correct |
45 |
Correct |
18 ms |
23808 KB |
Output is correct |
46 |
Correct |
18 ms |
23808 KB |
Output is correct |
47 |
Correct |
18 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
20 ms |
23936 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
18 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
18 ms |
23936 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
18 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
18 ms |
23936 KB |
Output is correct |
15 |
Correct |
18 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
18 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23928 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
22 ms |
23856 KB |
Output is correct |
22 |
Correct |
18 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
19 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23936 KB |
Output is correct |
26 |
Correct |
19 ms |
23808 KB |
Output is correct |
27 |
Correct |
19 ms |
23936 KB |
Output is correct |
28 |
Correct |
18 ms |
23936 KB |
Output is correct |
29 |
Correct |
18 ms |
23936 KB |
Output is correct |
30 |
Correct |
19 ms |
23936 KB |
Output is correct |
31 |
Correct |
18 ms |
23936 KB |
Output is correct |
32 |
Correct |
19 ms |
23936 KB |
Output is correct |
33 |
Correct |
20 ms |
24064 KB |
Output is correct |
34 |
Correct |
18 ms |
23808 KB |
Output is correct |
35 |
Correct |
19 ms |
23936 KB |
Output is correct |
36 |
Correct |
18 ms |
23936 KB |
Output is correct |
37 |
Correct |
20 ms |
23936 KB |
Output is correct |
38 |
Correct |
19 ms |
23936 KB |
Output is correct |
39 |
Correct |
19 ms |
23936 KB |
Output is correct |
40 |
Correct |
19 ms |
23936 KB |
Output is correct |
41 |
Correct |
19 ms |
23936 KB |
Output is correct |
42 |
Correct |
19 ms |
23936 KB |
Output is correct |
43 |
Correct |
19 ms |
23936 KB |
Output is correct |
44 |
Correct |
18 ms |
23808 KB |
Output is correct |
45 |
Correct |
18 ms |
23808 KB |
Output is correct |
46 |
Correct |
18 ms |
23808 KB |
Output is correct |
47 |
Correct |
18 ms |
23808 KB |
Output is correct |
48 |
Correct |
18 ms |
23808 KB |
Output is correct |
49 |
Correct |
19 ms |
23808 KB |
Output is correct |
50 |
Correct |
18 ms |
23808 KB |
Output is correct |
51 |
Correct |
18 ms |
23808 KB |
Output is correct |
52 |
Correct |
20 ms |
23808 KB |
Output is correct |
53 |
Correct |
19 ms |
23808 KB |
Output is correct |
54 |
Correct |
19 ms |
23808 KB |
Output is correct |
55 |
Correct |
18 ms |
23840 KB |
Output is correct |
56 |
Correct |
19 ms |
23808 KB |
Output is correct |
57 |
Correct |
18 ms |
23808 KB |
Output is correct |
58 |
Correct |
18 ms |
23808 KB |
Output is correct |
59 |
Correct |
18 ms |
23808 KB |
Output is correct |
60 |
Correct |
18 ms |
23936 KB |
Output is correct |
61 |
Correct |
18 ms |
23808 KB |
Output is correct |
62 |
Correct |
19 ms |
23936 KB |
Output is correct |
63 |
Correct |
20 ms |
23808 KB |
Output is correct |
64 |
Correct |
18 ms |
23808 KB |
Output is correct |
65 |
Correct |
18 ms |
23808 KB |
Output is correct |
66 |
Correct |
18 ms |
23808 KB |
Output is correct |
67 |
Correct |
19 ms |
23808 KB |
Output is correct |
68 |
Correct |
47 ms |
30076 KB |
Output is correct |
69 |
Correct |
74 ms |
35704 KB |
Output is correct |
70 |
Correct |
19 ms |
23808 KB |
Output is correct |
71 |
Correct |
97 ms |
41464 KB |
Output is correct |
72 |
Correct |
125 ms |
47096 KB |
Output is correct |
73 |
Correct |
153 ms |
52844 KB |
Output is correct |
74 |
Correct |
185 ms |
58364 KB |
Output is correct |
75 |
Correct |
211 ms |
64036 KB |
Output is correct |
76 |
Correct |
233 ms |
69752 KB |
Output is correct |
77 |
Correct |
257 ms |
75512 KB |
Output is correct |
78 |
Correct |
290 ms |
81016 KB |
Output is correct |
79 |
Correct |
309 ms |
86648 KB |
Output is correct |
80 |
Correct |
347 ms |
92280 KB |
Output is correct |
81 |
Correct |
19 ms |
23936 KB |
Output is correct |
82 |
Correct |
363 ms |
98144 KB |
Output is correct |
83 |
Correct |
393 ms |
103816 KB |
Output is correct |
84 |
Correct |
415 ms |
109560 KB |
Output is correct |
85 |
Correct |
444 ms |
115064 KB |
Output is correct |
86 |
Correct |
474 ms |
120568 KB |
Output is correct |
87 |
Correct |
493 ms |
126328 KB |
Output is correct |
88 |
Correct |
531 ms |
131832 KB |
Output is correct |
89 |
Correct |
558 ms |
137848 KB |
Output is correct |
90 |
Correct |
20 ms |
23808 KB |
Output is correct |
91 |
Correct |
18 ms |
23808 KB |
Output is correct |
92 |
Correct |
19 ms |
23808 KB |
Output is correct |
93 |
Correct |
19 ms |
23808 KB |
Output is correct |
94 |
Correct |
18 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
20 ms |
23936 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
18 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
18 ms |
23936 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
18 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
18 ms |
23936 KB |
Output is correct |
15 |
Correct |
18 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
18 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23928 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
22 ms |
23856 KB |
Output is correct |
22 |
Correct |
18 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
19 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23936 KB |
Output is correct |
26 |
Correct |
19 ms |
23808 KB |
Output is correct |
27 |
Correct |
19 ms |
23936 KB |
Output is correct |
28 |
Correct |
18 ms |
23936 KB |
Output is correct |
29 |
Correct |
18 ms |
23936 KB |
Output is correct |
30 |
Correct |
19 ms |
23936 KB |
Output is correct |
31 |
Correct |
18 ms |
23936 KB |
Output is correct |
32 |
Correct |
19 ms |
23936 KB |
Output is correct |
33 |
Correct |
20 ms |
24064 KB |
Output is correct |
34 |
Correct |
18 ms |
23808 KB |
Output is correct |
35 |
Correct |
19 ms |
23936 KB |
Output is correct |
36 |
Correct |
18 ms |
23936 KB |
Output is correct |
37 |
Correct |
20 ms |
23936 KB |
Output is correct |
38 |
Correct |
19 ms |
23936 KB |
Output is correct |
39 |
Correct |
19 ms |
23936 KB |
Output is correct |
40 |
Correct |
19 ms |
23936 KB |
Output is correct |
41 |
Correct |
19 ms |
23936 KB |
Output is correct |
42 |
Correct |
19 ms |
23936 KB |
Output is correct |
43 |
Correct |
19 ms |
23936 KB |
Output is correct |
44 |
Correct |
18 ms |
23808 KB |
Output is correct |
45 |
Correct |
18 ms |
23808 KB |
Output is correct |
46 |
Correct |
18 ms |
23808 KB |
Output is correct |
47 |
Correct |
18 ms |
23808 KB |
Output is correct |
48 |
Correct |
19 ms |
23936 KB |
Output is correct |
49 |
Incorrect |
20 ms |
23808 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
20 ms |
23936 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
18 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
18 ms |
23936 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
18 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
18 ms |
23936 KB |
Output is correct |
15 |
Correct |
18 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
18 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23928 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
22 ms |
23856 KB |
Output is correct |
22 |
Correct |
18 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
19 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23936 KB |
Output is correct |
26 |
Correct |
19 ms |
23808 KB |
Output is correct |
27 |
Correct |
19 ms |
23936 KB |
Output is correct |
28 |
Correct |
18 ms |
23936 KB |
Output is correct |
29 |
Correct |
18 ms |
23936 KB |
Output is correct |
30 |
Correct |
19 ms |
23936 KB |
Output is correct |
31 |
Correct |
18 ms |
23936 KB |
Output is correct |
32 |
Correct |
19 ms |
23936 KB |
Output is correct |
33 |
Correct |
20 ms |
24064 KB |
Output is correct |
34 |
Correct |
18 ms |
23808 KB |
Output is correct |
35 |
Correct |
19 ms |
23936 KB |
Output is correct |
36 |
Correct |
18 ms |
23936 KB |
Output is correct |
37 |
Correct |
20 ms |
23936 KB |
Output is correct |
38 |
Correct |
19 ms |
23936 KB |
Output is correct |
39 |
Correct |
19 ms |
23936 KB |
Output is correct |
40 |
Correct |
19 ms |
23936 KB |
Output is correct |
41 |
Correct |
19 ms |
23936 KB |
Output is correct |
42 |
Correct |
19 ms |
23936 KB |
Output is correct |
43 |
Correct |
19 ms |
23936 KB |
Output is correct |
44 |
Correct |
18 ms |
23808 KB |
Output is correct |
45 |
Correct |
18 ms |
23808 KB |
Output is correct |
46 |
Correct |
18 ms |
23808 KB |
Output is correct |
47 |
Correct |
18 ms |
23808 KB |
Output is correct |
48 |
Correct |
18 ms |
23808 KB |
Output is correct |
49 |
Correct |
19 ms |
23808 KB |
Output is correct |
50 |
Correct |
18 ms |
23808 KB |
Output is correct |
51 |
Correct |
18 ms |
23808 KB |
Output is correct |
52 |
Correct |
20 ms |
23808 KB |
Output is correct |
53 |
Correct |
19 ms |
23808 KB |
Output is correct |
54 |
Correct |
19 ms |
23808 KB |
Output is correct |
55 |
Correct |
18 ms |
23840 KB |
Output is correct |
56 |
Correct |
19 ms |
23808 KB |
Output is correct |
57 |
Correct |
18 ms |
23808 KB |
Output is correct |
58 |
Correct |
18 ms |
23808 KB |
Output is correct |
59 |
Correct |
18 ms |
23808 KB |
Output is correct |
60 |
Correct |
18 ms |
23936 KB |
Output is correct |
61 |
Correct |
18 ms |
23808 KB |
Output is correct |
62 |
Correct |
19 ms |
23936 KB |
Output is correct |
63 |
Correct |
20 ms |
23808 KB |
Output is correct |
64 |
Correct |
18 ms |
23808 KB |
Output is correct |
65 |
Correct |
18 ms |
23808 KB |
Output is correct |
66 |
Correct |
18 ms |
23808 KB |
Output is correct |
67 |
Correct |
19 ms |
23808 KB |
Output is correct |
68 |
Correct |
47 ms |
30076 KB |
Output is correct |
69 |
Correct |
74 ms |
35704 KB |
Output is correct |
70 |
Correct |
19 ms |
23808 KB |
Output is correct |
71 |
Correct |
97 ms |
41464 KB |
Output is correct |
72 |
Correct |
125 ms |
47096 KB |
Output is correct |
73 |
Correct |
153 ms |
52844 KB |
Output is correct |
74 |
Correct |
185 ms |
58364 KB |
Output is correct |
75 |
Correct |
211 ms |
64036 KB |
Output is correct |
76 |
Correct |
233 ms |
69752 KB |
Output is correct |
77 |
Correct |
257 ms |
75512 KB |
Output is correct |
78 |
Correct |
290 ms |
81016 KB |
Output is correct |
79 |
Correct |
309 ms |
86648 KB |
Output is correct |
80 |
Correct |
347 ms |
92280 KB |
Output is correct |
81 |
Correct |
19 ms |
23936 KB |
Output is correct |
82 |
Correct |
363 ms |
98144 KB |
Output is correct |
83 |
Correct |
393 ms |
103816 KB |
Output is correct |
84 |
Correct |
415 ms |
109560 KB |
Output is correct |
85 |
Correct |
444 ms |
115064 KB |
Output is correct |
86 |
Correct |
474 ms |
120568 KB |
Output is correct |
87 |
Correct |
493 ms |
126328 KB |
Output is correct |
88 |
Correct |
531 ms |
131832 KB |
Output is correct |
89 |
Correct |
558 ms |
137848 KB |
Output is correct |
90 |
Correct |
20 ms |
23808 KB |
Output is correct |
91 |
Correct |
18 ms |
23808 KB |
Output is correct |
92 |
Correct |
19 ms |
23808 KB |
Output is correct |
93 |
Correct |
19 ms |
23808 KB |
Output is correct |
94 |
Correct |
18 ms |
23808 KB |
Output is correct |
95 |
Correct |
19 ms |
23936 KB |
Output is correct |
96 |
Incorrect |
20 ms |
23808 KB |
Output isn't correct |
97 |
Halted |
0 ms |
0 KB |
- |