Submission #224426

# Submission time Handle Problem Language Result Execution time Memory
224426 2020-04-17T21:34:14 Z jhnah917 Traffic (IOI10_traffic) C++14
100 / 100
1342 ms 159476 KB
#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;

int n, sum;
int a[1010101];
int sz[1010101];
vector<int> g[1010101];
int cst[1010101];
int ans = -1;

void dfs(int v, int p = -1){
    sz[v] = a[v];
    for(auto i : g[v]) if(i ^ p){
        dfs(i, v); sz[v] += sz[i];
    }
}

void solve(int v, int p = -1){
    cst[v] = sum - sz[v];
    for(auto i : g[v]) if(i ^ p){
        cst[v] = max(cst[v], sz[i]);
        solve(i, v);
    }
    if(ans == -1 || cst[ans] > cst[v]) ans = v;
}

int LocateCentre(int N, int P[], int S[], int D[]){
    n = N;
    for(int i=1; i<=n; i++) a[i] = P[i-1], sum += a[i];
    for(int i=0; i<n-1; i++){
        int s = S[i] + 1, e = D[i] + 1;
        g[s].push_back(e); g[e].push_back(s);
    }
    dfs(1, -1); solve(1, -1);
    return ans - 1;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 24064 KB Output is correct
2 Correct 19 ms 24064 KB Output is correct
3 Correct 18 ms 24064 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 18 ms 24064 KB Output is correct
6 Correct 18 ms 24064 KB Output is correct
7 Correct 18 ms 24064 KB Output is correct
8 Correct 19 ms 24064 KB Output is correct
9 Correct 18 ms 24064 KB Output is correct
10 Correct 18 ms 24064 KB Output is correct
11 Correct 18 ms 24064 KB Output is correct
12 Correct 19 ms 24064 KB Output is correct
13 Correct 18 ms 24064 KB Output is correct
14 Correct 19 ms 24064 KB Output is correct
15 Correct 18 ms 24064 KB Output is correct
16 Correct 18 ms 24064 KB Output is correct
17 Correct 18 ms 24064 KB Output is correct
18 Correct 18 ms 24064 KB Output is correct
19 Correct 18 ms 24064 KB Output is correct
20 Correct 18 ms 24064 KB Output is correct
21 Correct 18 ms 24064 KB Output is correct
22 Correct 18 ms 24064 KB Output is correct
23 Correct 18 ms 24064 KB Output is correct
24 Correct 18 ms 24064 KB Output is correct
25 Correct 18 ms 24064 KB Output is correct
26 Correct 19 ms 24192 KB Output is correct
27 Correct 18 ms 24064 KB Output is correct
28 Correct 18 ms 24192 KB Output is correct
29 Correct 19 ms 24184 KB Output is correct
30 Correct 19 ms 24192 KB Output is correct
31 Correct 19 ms 24192 KB Output is correct
32 Correct 19 ms 24192 KB Output is correct
33 Correct 18 ms 24192 KB Output is correct
34 Correct 18 ms 24064 KB Output is correct
35 Correct 18 ms 24192 KB Output is correct
36 Correct 22 ms 24320 KB Output is correct
37 Correct 19 ms 24192 KB Output is correct
38 Correct 18 ms 24192 KB Output is correct
39 Correct 18 ms 24192 KB Output is correct
40 Correct 18 ms 24192 KB Output is correct
41 Correct 18 ms 24192 KB Output is correct
42 Correct 18 ms 24192 KB Output is correct
43 Correct 18 ms 24064 KB Output is correct
44 Correct 18 ms 24064 KB Output is correct
45 Correct 18 ms 24064 KB Output is correct
46 Correct 19 ms 24064 KB Output is correct
47 Correct 18 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 24064 KB Output is correct
2 Correct 19 ms 24064 KB Output is correct
3 Correct 18 ms 24064 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 18 ms 24064 KB Output is correct
6 Correct 18 ms 24064 KB Output is correct
7 Correct 18 ms 24064 KB Output is correct
8 Correct 19 ms 24064 KB Output is correct
9 Correct 18 ms 24064 KB Output is correct
10 Correct 18 ms 24064 KB Output is correct
11 Correct 18 ms 24064 KB Output is correct
12 Correct 19 ms 24064 KB Output is correct
13 Correct 18 ms 24064 KB Output is correct
14 Correct 19 ms 24064 KB Output is correct
15 Correct 18 ms 24064 KB Output is correct
16 Correct 18 ms 24064 KB Output is correct
17 Correct 18 ms 24064 KB Output is correct
18 Correct 18 ms 24064 KB Output is correct
19 Correct 18 ms 24064 KB Output is correct
20 Correct 18 ms 24064 KB Output is correct
21 Correct 18 ms 24064 KB Output is correct
22 Correct 18 ms 24064 KB Output is correct
23 Correct 18 ms 24064 KB Output is correct
24 Correct 18 ms 24064 KB Output is correct
25 Correct 18 ms 24064 KB Output is correct
26 Correct 19 ms 24192 KB Output is correct
27 Correct 18 ms 24064 KB Output is correct
28 Correct 18 ms 24192 KB Output is correct
29 Correct 19 ms 24184 KB Output is correct
30 Correct 19 ms 24192 KB Output is correct
31 Correct 19 ms 24192 KB Output is correct
32 Correct 19 ms 24192 KB Output is correct
33 Correct 18 ms 24192 KB Output is correct
34 Correct 18 ms 24064 KB Output is correct
35 Correct 18 ms 24192 KB Output is correct
36 Correct 22 ms 24320 KB Output is correct
37 Correct 19 ms 24192 KB Output is correct
38 Correct 18 ms 24192 KB Output is correct
39 Correct 18 ms 24192 KB Output is correct
40 Correct 18 ms 24192 KB Output is correct
41 Correct 18 ms 24192 KB Output is correct
42 Correct 18 ms 24192 KB Output is correct
43 Correct 18 ms 24064 KB Output is correct
44 Correct 18 ms 24064 KB Output is correct
45 Correct 18 ms 24064 KB Output is correct
46 Correct 19 ms 24064 KB Output is correct
47 Correct 18 ms 24064 KB Output is correct
48 Correct 17 ms 24064 KB Output is correct
49 Correct 17 ms 24064 KB Output is correct
50 Correct 18 ms 24064 KB Output is correct
51 Correct 18 ms 24064 KB Output is correct
52 Correct 19 ms 24104 KB Output is correct
53 Correct 18 ms 24064 KB Output is correct
54 Correct 18 ms 24064 KB Output is correct
55 Correct 18 ms 24064 KB Output is correct
56 Correct 18 ms 24064 KB Output is correct
57 Correct 18 ms 24064 KB Output is correct
58 Correct 19 ms 24064 KB Output is correct
59 Correct 18 ms 24064 KB Output is correct
60 Correct 18 ms 24064 KB Output is correct
61 Correct 18 ms 24064 KB Output is correct
62 Correct 18 ms 24064 KB Output is correct
63 Correct 17 ms 24064 KB Output is correct
64 Correct 18 ms 24064 KB Output is correct
65 Correct 17 ms 24064 KB Output is correct
66 Correct 18 ms 24064 KB Output is correct
67 Correct 18 ms 24064 KB Output is correct
68 Correct 45 ms 30840 KB Output is correct
69 Correct 73 ms 37500 KB Output is correct
70 Correct 18 ms 24064 KB Output is correct
71 Correct 103 ms 44280 KB Output is correct
72 Correct 128 ms 51060 KB Output is correct
73 Correct 155 ms 57848 KB Output is correct
74 Correct 184 ms 64764 KB Output is correct
75 Correct 208 ms 71416 KB Output is correct
76 Correct 235 ms 78200 KB Output is correct
77 Correct 283 ms 85240 KB Output is correct
78 Correct 293 ms 91768 KB Output is correct
79 Correct 319 ms 98552 KB Output is correct
80 Correct 350 ms 105208 KB Output is correct
81 Correct 18 ms 24064 KB Output is correct
82 Correct 379 ms 111992 KB Output is correct
83 Correct 405 ms 118776 KB Output is correct
84 Correct 438 ms 125692 KB Output is correct
85 Correct 459 ms 132344 KB Output is correct
86 Correct 499 ms 139124 KB Output is correct
87 Correct 515 ms 145784 KB Output is correct
88 Correct 567 ms 152564 KB Output is correct
89 Correct 585 ms 159476 KB Output is correct
90 Correct 18 ms 24064 KB Output is correct
91 Correct 18 ms 24064 KB Output is correct
92 Correct 18 ms 24064 KB Output is correct
93 Correct 18 ms 24064 KB Output is correct
94 Correct 18 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 24064 KB Output is correct
2 Correct 19 ms 24064 KB Output is correct
3 Correct 18 ms 24064 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 18 ms 24064 KB Output is correct
6 Correct 18 ms 24064 KB Output is correct
7 Correct 18 ms 24064 KB Output is correct
8 Correct 19 ms 24064 KB Output is correct
9 Correct 18 ms 24064 KB Output is correct
10 Correct 18 ms 24064 KB Output is correct
11 Correct 18 ms 24064 KB Output is correct
12 Correct 19 ms 24064 KB Output is correct
13 Correct 18 ms 24064 KB Output is correct
14 Correct 19 ms 24064 KB Output is correct
15 Correct 18 ms 24064 KB Output is correct
16 Correct 18 ms 24064 KB Output is correct
17 Correct 18 ms 24064 KB Output is correct
18 Correct 18 ms 24064 KB Output is correct
19 Correct 18 ms 24064 KB Output is correct
20 Correct 18 ms 24064 KB Output is correct
21 Correct 18 ms 24064 KB Output is correct
22 Correct 18 ms 24064 KB Output is correct
23 Correct 18 ms 24064 KB Output is correct
24 Correct 18 ms 24064 KB Output is correct
25 Correct 18 ms 24064 KB Output is correct
26 Correct 19 ms 24192 KB Output is correct
27 Correct 18 ms 24064 KB Output is correct
28 Correct 18 ms 24192 KB Output is correct
29 Correct 19 ms 24184 KB Output is correct
30 Correct 19 ms 24192 KB Output is correct
31 Correct 19 ms 24192 KB Output is correct
32 Correct 19 ms 24192 KB Output is correct
33 Correct 18 ms 24192 KB Output is correct
34 Correct 18 ms 24064 KB Output is correct
35 Correct 18 ms 24192 KB Output is correct
36 Correct 22 ms 24320 KB Output is correct
37 Correct 19 ms 24192 KB Output is correct
38 Correct 18 ms 24192 KB Output is correct
39 Correct 18 ms 24192 KB Output is correct
40 Correct 18 ms 24192 KB Output is correct
41 Correct 18 ms 24192 KB Output is correct
42 Correct 18 ms 24192 KB Output is correct
43 Correct 18 ms 24064 KB Output is correct
44 Correct 18 ms 24064 KB Output is correct
45 Correct 18 ms 24064 KB Output is correct
46 Correct 19 ms 24064 KB Output is correct
47 Correct 18 ms 24064 KB Output is correct
48 Correct 17 ms 24064 KB Output is correct
49 Correct 17 ms 24064 KB Output is correct
50 Correct 19 ms 24064 KB Output is correct
51 Correct 18 ms 24064 KB Output is correct
52 Correct 18 ms 24064 KB Output is correct
53 Correct 18 ms 24064 KB Output is correct
54 Correct 19 ms 24064 KB Output is correct
55 Correct 18 ms 24064 KB Output is correct
56 Correct 18 ms 24064 KB Output is correct
57 Correct 18 ms 24064 KB Output is correct
58 Correct 18 ms 24064 KB Output is correct
59 Correct 18 ms 24064 KB Output is correct
60 Correct 18 ms 24064 KB Output is correct
61 Correct 18 ms 24064 KB Output is correct
62 Correct 21 ms 24064 KB Output is correct
63 Correct 18 ms 24064 KB Output is correct
64 Correct 18 ms 24064 KB Output is correct
65 Correct 18 ms 24064 KB Output is correct
66 Correct 19 ms 24064 KB Output is correct
67 Correct 20 ms 24192 KB Output is correct
68 Correct 18 ms 24064 KB Output is correct
69 Correct 18 ms 24064 KB Output is correct
70 Correct 18 ms 24064 KB Output is correct
71 Correct 18 ms 24064 KB Output is correct
72 Correct 18 ms 24064 KB Output is correct
73 Correct 18 ms 24064 KB Output is correct
74 Correct 19 ms 24064 KB Output is correct
75 Correct 18 ms 24064 KB Output is correct
76 Correct 19 ms 24184 KB Output is correct
77 Correct 19 ms 24064 KB Output is correct
78 Correct 18 ms 24064 KB Output is correct
79 Correct 18 ms 24064 KB Output is correct
80 Correct 18 ms 24064 KB Output is correct
81 Correct 18 ms 24064 KB Output is correct
82 Correct 20 ms 24064 KB Output is correct
83 Correct 18 ms 24064 KB Output is correct
84 Correct 19 ms 24184 KB Output is correct
85 Correct 19 ms 24064 KB Output is correct
86 Correct 18 ms 24064 KB Output is correct
87 Correct 19 ms 24192 KB Output is correct
88 Correct 18 ms 24192 KB Output is correct
89 Correct 19 ms 24192 KB Output is correct
90 Correct 20 ms 24192 KB Output is correct
91 Correct 21 ms 24192 KB Output is correct
92 Correct 18 ms 24064 KB Output is correct
93 Correct 19 ms 24192 KB Output is correct
94 Correct 20 ms 24440 KB Output is correct
95 Correct 18 ms 24192 KB Output is correct
96 Correct 19 ms 24064 KB Output is correct
97 Correct 18 ms 24064 KB Output is correct
98 Correct 18 ms 24064 KB Output is correct
99 Correct 18 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 24064 KB Output is correct
2 Correct 19 ms 24064 KB Output is correct
3 Correct 18 ms 24064 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 18 ms 24064 KB Output is correct
6 Correct 18 ms 24064 KB Output is correct
7 Correct 18 ms 24064 KB Output is correct
8 Correct 19 ms 24064 KB Output is correct
9 Correct 18 ms 24064 KB Output is correct
10 Correct 18 ms 24064 KB Output is correct
11 Correct 18 ms 24064 KB Output is correct
12 Correct 19 ms 24064 KB Output is correct
13 Correct 18 ms 24064 KB Output is correct
14 Correct 19 ms 24064 KB Output is correct
15 Correct 18 ms 24064 KB Output is correct
16 Correct 18 ms 24064 KB Output is correct
17 Correct 18 ms 24064 KB Output is correct
18 Correct 18 ms 24064 KB Output is correct
19 Correct 18 ms 24064 KB Output is correct
20 Correct 18 ms 24064 KB Output is correct
21 Correct 18 ms 24064 KB Output is correct
22 Correct 18 ms 24064 KB Output is correct
23 Correct 18 ms 24064 KB Output is correct
24 Correct 18 ms 24064 KB Output is correct
25 Correct 18 ms 24064 KB Output is correct
26 Correct 19 ms 24192 KB Output is correct
27 Correct 18 ms 24064 KB Output is correct
28 Correct 18 ms 24192 KB Output is correct
29 Correct 19 ms 24184 KB Output is correct
30 Correct 19 ms 24192 KB Output is correct
31 Correct 19 ms 24192 KB Output is correct
32 Correct 19 ms 24192 KB Output is correct
33 Correct 18 ms 24192 KB Output is correct
34 Correct 18 ms 24064 KB Output is correct
35 Correct 18 ms 24192 KB Output is correct
36 Correct 22 ms 24320 KB Output is correct
37 Correct 19 ms 24192 KB Output is correct
38 Correct 18 ms 24192 KB Output is correct
39 Correct 18 ms 24192 KB Output is correct
40 Correct 18 ms 24192 KB Output is correct
41 Correct 18 ms 24192 KB Output is correct
42 Correct 18 ms 24192 KB Output is correct
43 Correct 18 ms 24064 KB Output is correct
44 Correct 18 ms 24064 KB Output is correct
45 Correct 18 ms 24064 KB Output is correct
46 Correct 19 ms 24064 KB Output is correct
47 Correct 18 ms 24064 KB Output is correct
48 Correct 17 ms 24064 KB Output is correct
49 Correct 17 ms 24064 KB Output is correct
50 Correct 18 ms 24064 KB Output is correct
51 Correct 18 ms 24064 KB Output is correct
52 Correct 19 ms 24104 KB Output is correct
53 Correct 18 ms 24064 KB Output is correct
54 Correct 18 ms 24064 KB Output is correct
55 Correct 18 ms 24064 KB Output is correct
56 Correct 18 ms 24064 KB Output is correct
57 Correct 18 ms 24064 KB Output is correct
58 Correct 19 ms 24064 KB Output is correct
59 Correct 18 ms 24064 KB Output is correct
60 Correct 18 ms 24064 KB Output is correct
61 Correct 18 ms 24064 KB Output is correct
62 Correct 18 ms 24064 KB Output is correct
63 Correct 17 ms 24064 KB Output is correct
64 Correct 18 ms 24064 KB Output is correct
65 Correct 17 ms 24064 KB Output is correct
66 Correct 18 ms 24064 KB Output is correct
67 Correct 18 ms 24064 KB Output is correct
68 Correct 45 ms 30840 KB Output is correct
69 Correct 73 ms 37500 KB Output is correct
70 Correct 18 ms 24064 KB Output is correct
71 Correct 103 ms 44280 KB Output is correct
72 Correct 128 ms 51060 KB Output is correct
73 Correct 155 ms 57848 KB Output is correct
74 Correct 184 ms 64764 KB Output is correct
75 Correct 208 ms 71416 KB Output is correct
76 Correct 235 ms 78200 KB Output is correct
77 Correct 283 ms 85240 KB Output is correct
78 Correct 293 ms 91768 KB Output is correct
79 Correct 319 ms 98552 KB Output is correct
80 Correct 350 ms 105208 KB Output is correct
81 Correct 18 ms 24064 KB Output is correct
82 Correct 379 ms 111992 KB Output is correct
83 Correct 405 ms 118776 KB Output is correct
84 Correct 438 ms 125692 KB Output is correct
85 Correct 459 ms 132344 KB Output is correct
86 Correct 499 ms 139124 KB Output is correct
87 Correct 515 ms 145784 KB Output is correct
88 Correct 567 ms 152564 KB Output is correct
89 Correct 585 ms 159476 KB Output is correct
90 Correct 18 ms 24064 KB Output is correct
91 Correct 18 ms 24064 KB Output is correct
92 Correct 18 ms 24064 KB Output is correct
93 Correct 18 ms 24064 KB Output is correct
94 Correct 18 ms 24064 KB Output is correct
95 Correct 17 ms 24064 KB Output is correct
96 Correct 17 ms 24064 KB Output is correct
97 Correct 19 ms 24064 KB Output is correct
98 Correct 18 ms 24064 KB Output is correct
99 Correct 18 ms 24064 KB Output is correct
100 Correct 18 ms 24064 KB Output is correct
101 Correct 19 ms 24064 KB Output is correct
102 Correct 18 ms 24064 KB Output is correct
103 Correct 18 ms 24064 KB Output is correct
104 Correct 18 ms 24064 KB Output is correct
105 Correct 18 ms 24064 KB Output is correct
106 Correct 18 ms 24064 KB Output is correct
107 Correct 18 ms 24064 KB Output is correct
108 Correct 18 ms 24064 KB Output is correct
109 Correct 21 ms 24064 KB Output is correct
110 Correct 18 ms 24064 KB Output is correct
111 Correct 18 ms 24064 KB Output is correct
112 Correct 18 ms 24064 KB Output is correct
113 Correct 19 ms 24064 KB Output is correct
114 Correct 20 ms 24192 KB Output is correct
115 Correct 18 ms 24064 KB Output is correct
116 Correct 18 ms 24064 KB Output is correct
117 Correct 18 ms 24064 KB Output is correct
118 Correct 18 ms 24064 KB Output is correct
119 Correct 18 ms 24064 KB Output is correct
120 Correct 18 ms 24064 KB Output is correct
121 Correct 19 ms 24064 KB Output is correct
122 Correct 18 ms 24064 KB Output is correct
123 Correct 19 ms 24184 KB Output is correct
124 Correct 19 ms 24064 KB Output is correct
125 Correct 18 ms 24064 KB Output is correct
126 Correct 18 ms 24064 KB Output is correct
127 Correct 18 ms 24064 KB Output is correct
128 Correct 18 ms 24064 KB Output is correct
129 Correct 20 ms 24064 KB Output is correct
130 Correct 18 ms 24064 KB Output is correct
131 Correct 19 ms 24184 KB Output is correct
132 Correct 19 ms 24064 KB Output is correct
133 Correct 18 ms 24064 KB Output is correct
134 Correct 19 ms 24192 KB Output is correct
135 Correct 18 ms 24192 KB Output is correct
136 Correct 19 ms 24192 KB Output is correct
137 Correct 20 ms 24192 KB Output is correct
138 Correct 21 ms 24192 KB Output is correct
139 Correct 18 ms 24064 KB Output is correct
140 Correct 19 ms 24192 KB Output is correct
141 Correct 20 ms 24440 KB Output is correct
142 Correct 18 ms 24192 KB Output is correct
143 Correct 19 ms 24064 KB Output is correct
144 Correct 18 ms 24064 KB Output is correct
145 Correct 18 ms 24064 KB Output is correct
146 Correct 18 ms 24064 KB Output is correct
147 Correct 18 ms 24064 KB Output is correct
148 Correct 18 ms 24064 KB Output is correct
149 Correct 17 ms 24192 KB Output is correct
150 Correct 18 ms 24064 KB Output is correct
151 Correct 18 ms 24064 KB Output is correct
152 Correct 18 ms 24064 KB Output is correct
153 Correct 18 ms 24064 KB Output is correct
154 Correct 18 ms 24064 KB Output is correct
155 Correct 18 ms 24064 KB Output is correct
156 Correct 18 ms 24064 KB Output is correct
157 Correct 18 ms 24064 KB Output is correct
158 Correct 17 ms 24064 KB Output is correct
159 Correct 18 ms 24064 KB Output is correct
160 Correct 18 ms 24064 KB Output is correct
161 Correct 18 ms 24064 KB Output is correct
162 Correct 18 ms 24064 KB Output is correct
163 Correct 18 ms 24064 KB Output is correct
164 Correct 18 ms 24064 KB Output is correct
165 Correct 24 ms 24320 KB Output is correct
166 Correct 18 ms 24064 KB Output is correct
167 Correct 18 ms 24064 KB Output is correct
168 Correct 18 ms 24064 KB Output is correct
169 Correct 18 ms 24064 KB Output is correct
170 Correct 18 ms 24064 KB Output is correct
171 Correct 51 ms 27768 KB Output is correct
172 Correct 112 ms 31532 KB Output is correct
173 Correct 162 ms 35064 KB Output is correct
174 Correct 219 ms 38648 KB Output is correct
175 Correct 318 ms 42488 KB Output is correct
176 Correct 355 ms 46072 KB Output is correct
177 Correct 442 ms 49912 KB Output is correct
178 Correct 495 ms 53368 KB Output is correct
179 Correct 570 ms 57080 KB Output is correct
180 Correct 18 ms 24064 KB Output is correct
181 Correct 640 ms 60768 KB Output is correct
182 Correct 698 ms 64376 KB Output is correct
183 Correct 774 ms 67960 KB Output is correct
184 Correct 872 ms 71672 KB Output is correct
185 Correct 921 ms 75384 KB Output is correct
186 Correct 989 ms 79184 KB Output is correct
187 Correct 1074 ms 82680 KB Output is correct
188 Correct 1137 ms 86520 KB Output is correct
189 Correct 1221 ms 89848 KB Output is correct
190 Correct 1293 ms 93556 KB Output is correct
191 Correct 18 ms 24064 KB Output is correct
192 Correct 1342 ms 97188 KB Output is correct
193 Correct 277 ms 90508 KB Output is correct
194 Correct 541 ms 156924 KB Output is correct
195 Correct 18 ms 24064 KB Output is correct
196 Correct 19 ms 24064 KB Output is correct
197 Correct 18 ms 24064 KB Output is correct
198 Correct 18 ms 24064 KB Output is correct