# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796133 |
2023-07-28T06:48:17 Z |
박영우(#10072) |
Security Guard (JOI23_guard) |
C++17 |
|
1264 ms |
1048576 KB |
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 301010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
vector<int> adj[MAX];
ll C[MAX];
ll ans = 0;
void dfs(int x, int p = 0) {
for (auto v : adj[x]) {
if (v == p) continue;
ans += C[x];
dfs(v, x);
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M, Q;
cin >> N >> M >> Q;
int i;
for (i = 1; i <= N; i++) cin >> C[i];
int a, b;
for (i = 1; i < N; i++) {
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, 0);
ll mx = 0;
for (i = 1; i <= N; i++) mx = max(mx, C[i]);
mx -= C[1];
if (mx < 0) mx = 0;
cout << ans + mx << ln;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
53 ms |
21756 KB |
Output is correct |
3 |
Correct |
54 ms |
21708 KB |
Output is correct |
4 |
Correct |
58 ms |
21756 KB |
Output is correct |
5 |
Correct |
60 ms |
21748 KB |
Output is correct |
6 |
Correct |
53 ms |
21744 KB |
Output is correct |
7 |
Correct |
54 ms |
21708 KB |
Output is correct |
8 |
Correct |
3 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
53 ms |
21756 KB |
Output is correct |
3 |
Correct |
54 ms |
21708 KB |
Output is correct |
4 |
Correct |
58 ms |
21756 KB |
Output is correct |
5 |
Correct |
60 ms |
21748 KB |
Output is correct |
6 |
Correct |
53 ms |
21744 KB |
Output is correct |
7 |
Correct |
54 ms |
21708 KB |
Output is correct |
8 |
Correct |
3 ms |
7380 KB |
Output is correct |
9 |
Correct |
3 ms |
7380 KB |
Output is correct |
10 |
Correct |
60 ms |
21816 KB |
Output is correct |
11 |
Correct |
63 ms |
21788 KB |
Output is correct |
12 |
Correct |
62 ms |
21756 KB |
Output is correct |
13 |
Correct |
61 ms |
21704 KB |
Output is correct |
14 |
Correct |
61 ms |
21688 KB |
Output is correct |
15 |
Correct |
60 ms |
21808 KB |
Output is correct |
16 |
Correct |
60 ms |
21732 KB |
Output is correct |
17 |
Correct |
61 ms |
21800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
53 ms |
21756 KB |
Output is correct |
3 |
Correct |
54 ms |
21708 KB |
Output is correct |
4 |
Correct |
58 ms |
21756 KB |
Output is correct |
5 |
Correct |
60 ms |
21748 KB |
Output is correct |
6 |
Correct |
53 ms |
21744 KB |
Output is correct |
7 |
Correct |
54 ms |
21708 KB |
Output is correct |
8 |
Correct |
3 ms |
7380 KB |
Output is correct |
9 |
Correct |
3 ms |
7380 KB |
Output is correct |
10 |
Correct |
60 ms |
21816 KB |
Output is correct |
11 |
Correct |
63 ms |
21788 KB |
Output is correct |
12 |
Correct |
62 ms |
21756 KB |
Output is correct |
13 |
Correct |
61 ms |
21704 KB |
Output is correct |
14 |
Correct |
61 ms |
21688 KB |
Output is correct |
15 |
Correct |
60 ms |
21808 KB |
Output is correct |
16 |
Correct |
60 ms |
21732 KB |
Output is correct |
17 |
Correct |
61 ms |
21800 KB |
Output is correct |
18 |
Correct |
3 ms |
7380 KB |
Output is correct |
19 |
Correct |
90 ms |
19304 KB |
Output is correct |
20 |
Correct |
130 ms |
17676 KB |
Output is correct |
21 |
Correct |
128 ms |
15256 KB |
Output is correct |
22 |
Correct |
80 ms |
15304 KB |
Output is correct |
23 |
Correct |
69 ms |
16016 KB |
Output is correct |
24 |
Correct |
75 ms |
16232 KB |
Output is correct |
25 |
Correct |
63 ms |
15952 KB |
Output is correct |
26 |
Correct |
60 ms |
15992 KB |
Output is correct |
27 |
Correct |
62 ms |
15996 KB |
Output is correct |
28 |
Correct |
97 ms |
19988 KB |
Output is correct |
29 |
Correct |
92 ms |
18616 KB |
Output is correct |
30 |
Correct |
66 ms |
16700 KB |
Output is correct |
31 |
Correct |
60 ms |
15952 KB |
Output is correct |
32 |
Correct |
90 ms |
15680 KB |
Output is correct |
33 |
Correct |
76 ms |
15164 KB |
Output is correct |
34 |
Correct |
80 ms |
15200 KB |
Output is correct |
35 |
Correct |
80 ms |
16156 KB |
Output is correct |
36 |
Correct |
99 ms |
16196 KB |
Output is correct |
37 |
Correct |
76 ms |
16184 KB |
Output is correct |
38 |
Correct |
106 ms |
17632 KB |
Output is correct |
39 |
Correct |
89 ms |
18872 KB |
Output is correct |
40 |
Correct |
89 ms |
16816 KB |
Output is correct |
41 |
Correct |
112 ms |
21392 KB |
Output is correct |
42 |
Correct |
111 ms |
21592 KB |
Output is correct |
43 |
Correct |
107 ms |
15436 KB |
Output is correct |
44 |
Correct |
116 ms |
15372 KB |
Output is correct |
45 |
Correct |
81 ms |
15388 KB |
Output is correct |
46 |
Correct |
80 ms |
15428 KB |
Output is correct |
47 |
Correct |
84 ms |
15312 KB |
Output is correct |
48 |
Correct |
86 ms |
15424 KB |
Output is correct |
49 |
Correct |
96 ms |
15368 KB |
Output is correct |
50 |
Correct |
110 ms |
15416 KB |
Output is correct |
51 |
Correct |
94 ms |
15420 KB |
Output is correct |
52 |
Correct |
72 ms |
15312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
53 ms |
21756 KB |
Output is correct |
3 |
Correct |
54 ms |
21708 KB |
Output is correct |
4 |
Correct |
58 ms |
21756 KB |
Output is correct |
5 |
Correct |
60 ms |
21748 KB |
Output is correct |
6 |
Correct |
53 ms |
21744 KB |
Output is correct |
7 |
Correct |
54 ms |
21708 KB |
Output is correct |
8 |
Correct |
3 ms |
7380 KB |
Output is correct |
9 |
Correct |
3 ms |
7380 KB |
Output is correct |
10 |
Correct |
60 ms |
21816 KB |
Output is correct |
11 |
Correct |
63 ms |
21788 KB |
Output is correct |
12 |
Correct |
62 ms |
21756 KB |
Output is correct |
13 |
Correct |
61 ms |
21704 KB |
Output is correct |
14 |
Correct |
61 ms |
21688 KB |
Output is correct |
15 |
Correct |
60 ms |
21808 KB |
Output is correct |
16 |
Correct |
60 ms |
21732 KB |
Output is correct |
17 |
Correct |
61 ms |
21800 KB |
Output is correct |
18 |
Correct |
3 ms |
7380 KB |
Output is correct |
19 |
Correct |
90 ms |
19304 KB |
Output is correct |
20 |
Correct |
130 ms |
17676 KB |
Output is correct |
21 |
Correct |
128 ms |
15256 KB |
Output is correct |
22 |
Correct |
80 ms |
15304 KB |
Output is correct |
23 |
Correct |
69 ms |
16016 KB |
Output is correct |
24 |
Correct |
75 ms |
16232 KB |
Output is correct |
25 |
Correct |
63 ms |
15952 KB |
Output is correct |
26 |
Correct |
60 ms |
15992 KB |
Output is correct |
27 |
Correct |
62 ms |
15996 KB |
Output is correct |
28 |
Correct |
97 ms |
19988 KB |
Output is correct |
29 |
Correct |
92 ms |
18616 KB |
Output is correct |
30 |
Correct |
66 ms |
16700 KB |
Output is correct |
31 |
Correct |
60 ms |
15952 KB |
Output is correct |
32 |
Correct |
90 ms |
15680 KB |
Output is correct |
33 |
Correct |
76 ms |
15164 KB |
Output is correct |
34 |
Correct |
80 ms |
15200 KB |
Output is correct |
35 |
Correct |
80 ms |
16156 KB |
Output is correct |
36 |
Correct |
99 ms |
16196 KB |
Output is correct |
37 |
Correct |
76 ms |
16184 KB |
Output is correct |
38 |
Correct |
106 ms |
17632 KB |
Output is correct |
39 |
Correct |
89 ms |
18872 KB |
Output is correct |
40 |
Correct |
89 ms |
16816 KB |
Output is correct |
41 |
Correct |
112 ms |
21392 KB |
Output is correct |
42 |
Correct |
111 ms |
21592 KB |
Output is correct |
43 |
Correct |
107 ms |
15436 KB |
Output is correct |
44 |
Correct |
116 ms |
15372 KB |
Output is correct |
45 |
Correct |
81 ms |
15388 KB |
Output is correct |
46 |
Correct |
80 ms |
15428 KB |
Output is correct |
47 |
Correct |
84 ms |
15312 KB |
Output is correct |
48 |
Correct |
86 ms |
15424 KB |
Output is correct |
49 |
Correct |
96 ms |
15368 KB |
Output is correct |
50 |
Correct |
110 ms |
15416 KB |
Output is correct |
51 |
Correct |
94 ms |
15420 KB |
Output is correct |
52 |
Correct |
72 ms |
15312 KB |
Output is correct |
53 |
Correct |
4 ms |
7380 KB |
Output is correct |
54 |
Runtime error |
1264 ms |
1048576 KB |
Execution killed with signal 9 |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Incorrect |
3 ms |
7380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Incorrect |
3 ms |
7380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
53 ms |
21756 KB |
Output is correct |
3 |
Correct |
54 ms |
21708 KB |
Output is correct |
4 |
Correct |
58 ms |
21756 KB |
Output is correct |
5 |
Correct |
60 ms |
21748 KB |
Output is correct |
6 |
Correct |
53 ms |
21744 KB |
Output is correct |
7 |
Correct |
54 ms |
21708 KB |
Output is correct |
8 |
Correct |
3 ms |
7380 KB |
Output is correct |
9 |
Correct |
3 ms |
7380 KB |
Output is correct |
10 |
Correct |
60 ms |
21816 KB |
Output is correct |
11 |
Correct |
63 ms |
21788 KB |
Output is correct |
12 |
Correct |
62 ms |
21756 KB |
Output is correct |
13 |
Correct |
61 ms |
21704 KB |
Output is correct |
14 |
Correct |
61 ms |
21688 KB |
Output is correct |
15 |
Correct |
60 ms |
21808 KB |
Output is correct |
16 |
Correct |
60 ms |
21732 KB |
Output is correct |
17 |
Correct |
61 ms |
21800 KB |
Output is correct |
18 |
Correct |
3 ms |
7380 KB |
Output is correct |
19 |
Correct |
90 ms |
19304 KB |
Output is correct |
20 |
Correct |
130 ms |
17676 KB |
Output is correct |
21 |
Correct |
128 ms |
15256 KB |
Output is correct |
22 |
Correct |
80 ms |
15304 KB |
Output is correct |
23 |
Correct |
69 ms |
16016 KB |
Output is correct |
24 |
Correct |
75 ms |
16232 KB |
Output is correct |
25 |
Correct |
63 ms |
15952 KB |
Output is correct |
26 |
Correct |
60 ms |
15992 KB |
Output is correct |
27 |
Correct |
62 ms |
15996 KB |
Output is correct |
28 |
Correct |
97 ms |
19988 KB |
Output is correct |
29 |
Correct |
92 ms |
18616 KB |
Output is correct |
30 |
Correct |
66 ms |
16700 KB |
Output is correct |
31 |
Correct |
60 ms |
15952 KB |
Output is correct |
32 |
Correct |
90 ms |
15680 KB |
Output is correct |
33 |
Correct |
76 ms |
15164 KB |
Output is correct |
34 |
Correct |
80 ms |
15200 KB |
Output is correct |
35 |
Correct |
80 ms |
16156 KB |
Output is correct |
36 |
Correct |
99 ms |
16196 KB |
Output is correct |
37 |
Correct |
76 ms |
16184 KB |
Output is correct |
38 |
Correct |
106 ms |
17632 KB |
Output is correct |
39 |
Correct |
89 ms |
18872 KB |
Output is correct |
40 |
Correct |
89 ms |
16816 KB |
Output is correct |
41 |
Correct |
112 ms |
21392 KB |
Output is correct |
42 |
Correct |
111 ms |
21592 KB |
Output is correct |
43 |
Correct |
107 ms |
15436 KB |
Output is correct |
44 |
Correct |
116 ms |
15372 KB |
Output is correct |
45 |
Correct |
81 ms |
15388 KB |
Output is correct |
46 |
Correct |
80 ms |
15428 KB |
Output is correct |
47 |
Correct |
84 ms |
15312 KB |
Output is correct |
48 |
Correct |
86 ms |
15424 KB |
Output is correct |
49 |
Correct |
96 ms |
15368 KB |
Output is correct |
50 |
Correct |
110 ms |
15416 KB |
Output is correct |
51 |
Correct |
94 ms |
15420 KB |
Output is correct |
52 |
Correct |
72 ms |
15312 KB |
Output is correct |
53 |
Correct |
4 ms |
7380 KB |
Output is correct |
54 |
Runtime error |
1264 ms |
1048576 KB |
Execution killed with signal 9 |
55 |
Halted |
0 ms |
0 KB |
- |