#include <bits/stdc++.h>
#include "traffic.h"
#define pb push_back
#define ll int
using namespace std;
vector<vector<int>> adj(1000000,vector<int>());
map<pair<int,int>,ll> m;
int* P;
ll dp(int p,int c){
if(m.find((pair<int,int>){p,c})!=m.end())return m[(pair<int,int>){p,c}];
ll ans = P[c];
for(int v:adj[c]){
if(v==p)continue;
ans += dp(c,v);
}
m.insert({{p,c},ans});
return ans;
}
int LocateCentre(int n,int p[],int s[],int d[]){
for(int i=0;i<n-1;i++){
adj.at(s[i]).pb(d[i]);
adj.at(d[i]).pb(s[i]);
}
P = p;
ll ans = INT_MAX;
int index = -1;
for(int i=0;i<n;i++){
ll local = INT_MIN;
for(int v:adj[i])local = max(local,dp(i,v));
if(local<ans){
ans = local;
index = i;
}
}
return index;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23788 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
18 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23788 KB |
Output is correct |
8 |
Correct |
16 ms |
23788 KB |
Output is correct |
9 |
Correct |
29 ms |
23788 KB |
Output is correct |
10 |
Correct |
20 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
16 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Correct |
16 ms |
23788 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
16 ms |
23788 KB |
Output is correct |
19 |
Correct |
16 ms |
23788 KB |
Output is correct |
20 |
Correct |
17 ms |
23788 KB |
Output is correct |
21 |
Correct |
17 ms |
23808 KB |
Output is correct |
22 |
Correct |
17 ms |
23788 KB |
Output is correct |
23 |
Correct |
16 ms |
23788 KB |
Output is correct |
24 |
Correct |
17 ms |
23788 KB |
Output is correct |
25 |
Correct |
18 ms |
23916 KB |
Output is correct |
26 |
Correct |
17 ms |
23936 KB |
Output is correct |
27 |
Correct |
17 ms |
23916 KB |
Output is correct |
28 |
Correct |
17 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23916 KB |
Output is correct |
30 |
Correct |
17 ms |
23916 KB |
Output is correct |
31 |
Correct |
17 ms |
23916 KB |
Output is correct |
32 |
Correct |
19 ms |
23916 KB |
Output is correct |
33 |
Correct |
20 ms |
23916 KB |
Output is correct |
34 |
Correct |
19 ms |
23788 KB |
Output is correct |
35 |
Correct |
17 ms |
23916 KB |
Output is correct |
36 |
Correct |
17 ms |
24036 KB |
Output is correct |
37 |
Correct |
18 ms |
24044 KB |
Output is correct |
38 |
Correct |
17 ms |
24044 KB |
Output is correct |
39 |
Correct |
17 ms |
24044 KB |
Output is correct |
40 |
Correct |
18 ms |
24044 KB |
Output is correct |
41 |
Correct |
17 ms |
24044 KB |
Output is correct |
42 |
Correct |
17 ms |
24044 KB |
Output is correct |
43 |
Correct |
16 ms |
23788 KB |
Output is correct |
44 |
Correct |
17 ms |
23788 KB |
Output is correct |
45 |
Correct |
17 ms |
23788 KB |
Output is correct |
46 |
Correct |
20 ms |
23788 KB |
Output is correct |
47 |
Correct |
17 ms |
23788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23788 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
18 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23788 KB |
Output is correct |
8 |
Correct |
16 ms |
23788 KB |
Output is correct |
9 |
Correct |
29 ms |
23788 KB |
Output is correct |
10 |
Correct |
20 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
16 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Correct |
16 ms |
23788 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
16 ms |
23788 KB |
Output is correct |
19 |
Correct |
16 ms |
23788 KB |
Output is correct |
20 |
Correct |
17 ms |
23788 KB |
Output is correct |
21 |
Correct |
17 ms |
23808 KB |
Output is correct |
22 |
Correct |
17 ms |
23788 KB |
Output is correct |
23 |
Correct |
16 ms |
23788 KB |
Output is correct |
24 |
Correct |
17 ms |
23788 KB |
Output is correct |
25 |
Correct |
18 ms |
23916 KB |
Output is correct |
26 |
Correct |
17 ms |
23936 KB |
Output is correct |
27 |
Correct |
17 ms |
23916 KB |
Output is correct |
28 |
Correct |
17 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23916 KB |
Output is correct |
30 |
Correct |
17 ms |
23916 KB |
Output is correct |
31 |
Correct |
17 ms |
23916 KB |
Output is correct |
32 |
Correct |
19 ms |
23916 KB |
Output is correct |
33 |
Correct |
20 ms |
23916 KB |
Output is correct |
34 |
Correct |
19 ms |
23788 KB |
Output is correct |
35 |
Correct |
17 ms |
23916 KB |
Output is correct |
36 |
Correct |
17 ms |
24036 KB |
Output is correct |
37 |
Correct |
18 ms |
24044 KB |
Output is correct |
38 |
Correct |
17 ms |
24044 KB |
Output is correct |
39 |
Correct |
17 ms |
24044 KB |
Output is correct |
40 |
Correct |
18 ms |
24044 KB |
Output is correct |
41 |
Correct |
17 ms |
24044 KB |
Output is correct |
42 |
Correct |
17 ms |
24044 KB |
Output is correct |
43 |
Correct |
16 ms |
23788 KB |
Output is correct |
44 |
Correct |
17 ms |
23788 KB |
Output is correct |
45 |
Correct |
17 ms |
23788 KB |
Output is correct |
46 |
Correct |
20 ms |
23788 KB |
Output is correct |
47 |
Correct |
17 ms |
23788 KB |
Output is correct |
48 |
Correct |
18 ms |
23916 KB |
Output is correct |
49 |
Correct |
19 ms |
23932 KB |
Output is correct |
50 |
Correct |
16 ms |
23788 KB |
Output is correct |
51 |
Correct |
17 ms |
23788 KB |
Output is correct |
52 |
Correct |
19 ms |
23788 KB |
Output is correct |
53 |
Correct |
17 ms |
23788 KB |
Output is correct |
54 |
Correct |
17 ms |
23788 KB |
Output is correct |
55 |
Correct |
16 ms |
23788 KB |
Output is correct |
56 |
Correct |
17 ms |
23916 KB |
Output is correct |
57 |
Correct |
17 ms |
23788 KB |
Output is correct |
58 |
Correct |
17 ms |
23788 KB |
Output is correct |
59 |
Correct |
17 ms |
23788 KB |
Output is correct |
60 |
Correct |
16 ms |
23788 KB |
Output is correct |
61 |
Correct |
16 ms |
23788 KB |
Output is correct |
62 |
Correct |
17 ms |
23788 KB |
Output is correct |
63 |
Correct |
17 ms |
23788 KB |
Output is correct |
64 |
Correct |
19 ms |
23808 KB |
Output is correct |
65 |
Correct |
17 ms |
23788 KB |
Output is correct |
66 |
Correct |
18 ms |
23788 KB |
Output is correct |
67 |
Correct |
17 ms |
23788 KB |
Output is correct |
68 |
Correct |
92 ms |
36844 KB |
Output is correct |
69 |
Correct |
164 ms |
49388 KB |
Output is correct |
70 |
Correct |
17 ms |
23788 KB |
Output is correct |
71 |
Correct |
243 ms |
61676 KB |
Output is correct |
72 |
Correct |
320 ms |
73964 KB |
Output is correct |
73 |
Correct |
403 ms |
86136 KB |
Output is correct |
74 |
Correct |
484 ms |
98540 KB |
Output is correct |
75 |
Correct |
562 ms |
110836 KB |
Output is correct |
76 |
Correct |
658 ms |
123288 KB |
Output is correct |
77 |
Correct |
792 ms |
135692 KB |
Output is correct |
78 |
Correct |
812 ms |
147948 KB |
Output is correct |
79 |
Correct |
960 ms |
160108 KB |
Output is correct |
80 |
Correct |
1010 ms |
172796 KB |
Output is correct |
81 |
Correct |
16 ms |
23788 KB |
Output is correct |
82 |
Correct |
1079 ms |
185452 KB |
Output is correct |
83 |
Correct |
1152 ms |
198524 KB |
Output is correct |
84 |
Correct |
1227 ms |
210924 KB |
Output is correct |
85 |
Correct |
1318 ms |
222828 KB |
Output is correct |
86 |
Correct |
1425 ms |
235188 KB |
Output is correct |
87 |
Correct |
1512 ms |
248684 KB |
Output is correct |
88 |
Correct |
1571 ms |
258592 KB |
Output is correct |
89 |
Runtime error |
1507 ms |
262148 KB |
Execution killed with signal 9 |
90 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23788 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
18 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23788 KB |
Output is correct |
8 |
Correct |
16 ms |
23788 KB |
Output is correct |
9 |
Correct |
29 ms |
23788 KB |
Output is correct |
10 |
Correct |
20 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
16 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Correct |
16 ms |
23788 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
16 ms |
23788 KB |
Output is correct |
19 |
Correct |
16 ms |
23788 KB |
Output is correct |
20 |
Correct |
17 ms |
23788 KB |
Output is correct |
21 |
Correct |
17 ms |
23808 KB |
Output is correct |
22 |
Correct |
17 ms |
23788 KB |
Output is correct |
23 |
Correct |
16 ms |
23788 KB |
Output is correct |
24 |
Correct |
17 ms |
23788 KB |
Output is correct |
25 |
Correct |
18 ms |
23916 KB |
Output is correct |
26 |
Correct |
17 ms |
23936 KB |
Output is correct |
27 |
Correct |
17 ms |
23916 KB |
Output is correct |
28 |
Correct |
17 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23916 KB |
Output is correct |
30 |
Correct |
17 ms |
23916 KB |
Output is correct |
31 |
Correct |
17 ms |
23916 KB |
Output is correct |
32 |
Correct |
19 ms |
23916 KB |
Output is correct |
33 |
Correct |
20 ms |
23916 KB |
Output is correct |
34 |
Correct |
19 ms |
23788 KB |
Output is correct |
35 |
Correct |
17 ms |
23916 KB |
Output is correct |
36 |
Correct |
17 ms |
24036 KB |
Output is correct |
37 |
Correct |
18 ms |
24044 KB |
Output is correct |
38 |
Correct |
17 ms |
24044 KB |
Output is correct |
39 |
Correct |
17 ms |
24044 KB |
Output is correct |
40 |
Correct |
18 ms |
24044 KB |
Output is correct |
41 |
Correct |
17 ms |
24044 KB |
Output is correct |
42 |
Correct |
17 ms |
24044 KB |
Output is correct |
43 |
Correct |
16 ms |
23788 KB |
Output is correct |
44 |
Correct |
17 ms |
23788 KB |
Output is correct |
45 |
Correct |
17 ms |
23788 KB |
Output is correct |
46 |
Correct |
20 ms |
23788 KB |
Output is correct |
47 |
Correct |
17 ms |
23788 KB |
Output is correct |
48 |
Correct |
19 ms |
23788 KB |
Output is correct |
49 |
Correct |
16 ms |
23788 KB |
Output is correct |
50 |
Correct |
18 ms |
23776 KB |
Output is correct |
51 |
Correct |
16 ms |
23788 KB |
Output is correct |
52 |
Correct |
18 ms |
23788 KB |
Output is correct |
53 |
Correct |
16 ms |
23788 KB |
Output is correct |
54 |
Correct |
17 ms |
23916 KB |
Output is correct |
55 |
Correct |
16 ms |
23788 KB |
Output is correct |
56 |
Correct |
16 ms |
23788 KB |
Output is correct |
57 |
Correct |
16 ms |
23788 KB |
Output is correct |
58 |
Correct |
17 ms |
23788 KB |
Output is correct |
59 |
Correct |
16 ms |
23788 KB |
Output is correct |
60 |
Correct |
18 ms |
23788 KB |
Output is correct |
61 |
Correct |
17 ms |
23788 KB |
Output is correct |
62 |
Correct |
17 ms |
23788 KB |
Output is correct |
63 |
Correct |
16 ms |
23788 KB |
Output is correct |
64 |
Correct |
16 ms |
23788 KB |
Output is correct |
65 |
Correct |
16 ms |
23788 KB |
Output is correct |
66 |
Correct |
16 ms |
23788 KB |
Output is correct |
67 |
Correct |
17 ms |
23788 KB |
Output is correct |
68 |
Correct |
17 ms |
24044 KB |
Output is correct |
69 |
Correct |
17 ms |
23872 KB |
Output is correct |
70 |
Correct |
18 ms |
23936 KB |
Output is correct |
71 |
Correct |
16 ms |
23788 KB |
Output is correct |
72 |
Correct |
17 ms |
23788 KB |
Output is correct |
73 |
Correct |
17 ms |
23788 KB |
Output is correct |
74 |
Correct |
17 ms |
23788 KB |
Output is correct |
75 |
Correct |
16 ms |
23788 KB |
Output is correct |
76 |
Correct |
17 ms |
23916 KB |
Output is correct |
77 |
Correct |
17 ms |
23916 KB |
Output is correct |
78 |
Correct |
17 ms |
23916 KB |
Output is correct |
79 |
Correct |
17 ms |
23916 KB |
Output is correct |
80 |
Correct |
17 ms |
23916 KB |
Output is correct |
81 |
Correct |
17 ms |
23788 KB |
Output is correct |
82 |
Correct |
18 ms |
23916 KB |
Output is correct |
83 |
Correct |
18 ms |
23916 KB |
Output is correct |
84 |
Correct |
18 ms |
23916 KB |
Output is correct |
85 |
Correct |
19 ms |
23916 KB |
Output is correct |
86 |
Correct |
21 ms |
23916 KB |
Output is correct |
87 |
Correct |
20 ms |
23916 KB |
Output is correct |
88 |
Correct |
21 ms |
23916 KB |
Output is correct |
89 |
Correct |
20 ms |
23916 KB |
Output is correct |
90 |
Correct |
19 ms |
23916 KB |
Output is correct |
91 |
Correct |
18 ms |
24044 KB |
Output is correct |
92 |
Correct |
17 ms |
23788 KB |
Output is correct |
93 |
Correct |
20 ms |
24044 KB |
Output is correct |
94 |
Correct |
17 ms |
23916 KB |
Output is correct |
95 |
Correct |
17 ms |
24044 KB |
Output is correct |
96 |
Correct |
20 ms |
23788 KB |
Output is correct |
97 |
Correct |
16 ms |
23788 KB |
Output is correct |
98 |
Correct |
23 ms |
23788 KB |
Output is correct |
99 |
Correct |
22 ms |
23788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23788 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
18 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23788 KB |
Output is correct |
8 |
Correct |
16 ms |
23788 KB |
Output is correct |
9 |
Correct |
29 ms |
23788 KB |
Output is correct |
10 |
Correct |
20 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
16 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Correct |
16 ms |
23788 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
16 ms |
23788 KB |
Output is correct |
19 |
Correct |
16 ms |
23788 KB |
Output is correct |
20 |
Correct |
17 ms |
23788 KB |
Output is correct |
21 |
Correct |
17 ms |
23808 KB |
Output is correct |
22 |
Correct |
17 ms |
23788 KB |
Output is correct |
23 |
Correct |
16 ms |
23788 KB |
Output is correct |
24 |
Correct |
17 ms |
23788 KB |
Output is correct |
25 |
Correct |
18 ms |
23916 KB |
Output is correct |
26 |
Correct |
17 ms |
23936 KB |
Output is correct |
27 |
Correct |
17 ms |
23916 KB |
Output is correct |
28 |
Correct |
17 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23916 KB |
Output is correct |
30 |
Correct |
17 ms |
23916 KB |
Output is correct |
31 |
Correct |
17 ms |
23916 KB |
Output is correct |
32 |
Correct |
19 ms |
23916 KB |
Output is correct |
33 |
Correct |
20 ms |
23916 KB |
Output is correct |
34 |
Correct |
19 ms |
23788 KB |
Output is correct |
35 |
Correct |
17 ms |
23916 KB |
Output is correct |
36 |
Correct |
17 ms |
24036 KB |
Output is correct |
37 |
Correct |
18 ms |
24044 KB |
Output is correct |
38 |
Correct |
17 ms |
24044 KB |
Output is correct |
39 |
Correct |
17 ms |
24044 KB |
Output is correct |
40 |
Correct |
18 ms |
24044 KB |
Output is correct |
41 |
Correct |
17 ms |
24044 KB |
Output is correct |
42 |
Correct |
17 ms |
24044 KB |
Output is correct |
43 |
Correct |
16 ms |
23788 KB |
Output is correct |
44 |
Correct |
17 ms |
23788 KB |
Output is correct |
45 |
Correct |
17 ms |
23788 KB |
Output is correct |
46 |
Correct |
20 ms |
23788 KB |
Output is correct |
47 |
Correct |
17 ms |
23788 KB |
Output is correct |
48 |
Correct |
18 ms |
23916 KB |
Output is correct |
49 |
Correct |
19 ms |
23932 KB |
Output is correct |
50 |
Correct |
16 ms |
23788 KB |
Output is correct |
51 |
Correct |
17 ms |
23788 KB |
Output is correct |
52 |
Correct |
19 ms |
23788 KB |
Output is correct |
53 |
Correct |
17 ms |
23788 KB |
Output is correct |
54 |
Correct |
17 ms |
23788 KB |
Output is correct |
55 |
Correct |
16 ms |
23788 KB |
Output is correct |
56 |
Correct |
17 ms |
23916 KB |
Output is correct |
57 |
Correct |
17 ms |
23788 KB |
Output is correct |
58 |
Correct |
17 ms |
23788 KB |
Output is correct |
59 |
Correct |
17 ms |
23788 KB |
Output is correct |
60 |
Correct |
16 ms |
23788 KB |
Output is correct |
61 |
Correct |
16 ms |
23788 KB |
Output is correct |
62 |
Correct |
17 ms |
23788 KB |
Output is correct |
63 |
Correct |
17 ms |
23788 KB |
Output is correct |
64 |
Correct |
19 ms |
23808 KB |
Output is correct |
65 |
Correct |
17 ms |
23788 KB |
Output is correct |
66 |
Correct |
18 ms |
23788 KB |
Output is correct |
67 |
Correct |
17 ms |
23788 KB |
Output is correct |
68 |
Correct |
92 ms |
36844 KB |
Output is correct |
69 |
Correct |
164 ms |
49388 KB |
Output is correct |
70 |
Correct |
17 ms |
23788 KB |
Output is correct |
71 |
Correct |
243 ms |
61676 KB |
Output is correct |
72 |
Correct |
320 ms |
73964 KB |
Output is correct |
73 |
Correct |
403 ms |
86136 KB |
Output is correct |
74 |
Correct |
484 ms |
98540 KB |
Output is correct |
75 |
Correct |
562 ms |
110836 KB |
Output is correct |
76 |
Correct |
658 ms |
123288 KB |
Output is correct |
77 |
Correct |
792 ms |
135692 KB |
Output is correct |
78 |
Correct |
812 ms |
147948 KB |
Output is correct |
79 |
Correct |
960 ms |
160108 KB |
Output is correct |
80 |
Correct |
1010 ms |
172796 KB |
Output is correct |
81 |
Correct |
16 ms |
23788 KB |
Output is correct |
82 |
Correct |
1079 ms |
185452 KB |
Output is correct |
83 |
Correct |
1152 ms |
198524 KB |
Output is correct |
84 |
Correct |
1227 ms |
210924 KB |
Output is correct |
85 |
Correct |
1318 ms |
222828 KB |
Output is correct |
86 |
Correct |
1425 ms |
235188 KB |
Output is correct |
87 |
Correct |
1512 ms |
248684 KB |
Output is correct |
88 |
Correct |
1571 ms |
258592 KB |
Output is correct |
89 |
Runtime error |
1507 ms |
262148 KB |
Execution killed with signal 9 |
90 |
Halted |
0 ms |
0 KB |
- |