# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796180 |
2023-07-28T07:31:03 Z |
GEN 이지후(#10112) |
Security Guard (JOI23_guard) |
C++17 |
|
180 ms |
150348 KB |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<int, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
const int MAXN = 200005;
// case tree:
// root with maximum
// anchor in parent
// using the guard from root, can do everything
struct disj {
int pa[MAXN];
void init(int n) { iota(pa, pa + n + 1, 0); }
int find(int x) { return pa[x] = (pa[x] == x ? x : find(pa[x])); }
bool uni(int p, int q) {
p = find(p);
q = find(q);
if (p == q)
return 0;
pa[q] = p;
return 1;
}
} disj;
vector<pi> gph[MAXN];
const int MAXC = 3005;
lint a[MAXN];
lint dp[MAXC][MAXC][2], aux[MAXC][2]; // one for each sub
int sz[MAXN];
void dfs(int x, int p) {
sz[x] = 1;
dp[x][0][0] = 0;
dp[x][0][1] = a[x];
for (auto &[w, y] : gph[x]) {
if (y == p)
continue;
dfs(y, x);
memset(aux, 0x3f, sizeof(aux));
for (int i = 0; i < sz[y]; i++) {
dp[y][i + 1][0] = min(dp[y][i + 1][0], dp[y][i][1] - w);
}
for (int i = 0; i <= sz[x]; i++) {
for (int j = 0; j <= sz[y]; j++) {
for (int k = 0; k < 2; k++) {
for (int l = 0; k + l < 2; l++) {
aux[i + j][k + l] = min(aux[i + j][k + l], dp[x][i][k] + dp[y][j][l]);
}
}
}
}
sz[x] += sz[y];
for (int i = 0; i <= sz[x]; i++) {
dp[x][i][0] = aux[i][0];
dp[x][i][1] = aux[i][1];
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<array<int, 3>> edges(m);
for (auto &[x, s, e] : edges) {
cin >> s >> e;
s--;
e--;
x = a[s] + a[e];
}
sort(all(edges));
lint ans = -accumulate(a, a + n, 0ll) + *max_element(a, a + n);
disj.init(n);
for (auto &[x, s, e] : edges) {
if (disj.uni(s, e)) {
ans += x;
gph[s].push_back({x, e});
gph[e].push_back({x, s});
}
}
cout << ans << "\n";
if (q > 0) {
int rt = min_element(a, a + n) - a;
memset(dp, 0x3f, sizeof(dp));
dfs(rt, -1);
for (int i = 1; i <= q; i++) {
cout << ans + a[rt] * i + dp[rt][i][0] << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
60 ms |
15916 KB |
Output is correct |
3 |
Correct |
59 ms |
15896 KB |
Output is correct |
4 |
Correct |
78 ms |
15868 KB |
Output is correct |
5 |
Correct |
69 ms |
15852 KB |
Output is correct |
6 |
Correct |
70 ms |
15908 KB |
Output is correct |
7 |
Correct |
70 ms |
15852 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
60 ms |
15916 KB |
Output is correct |
3 |
Correct |
59 ms |
15896 KB |
Output is correct |
4 |
Correct |
78 ms |
15868 KB |
Output is correct |
5 |
Correct |
69 ms |
15852 KB |
Output is correct |
6 |
Correct |
70 ms |
15908 KB |
Output is correct |
7 |
Correct |
70 ms |
15852 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
116 ms |
16000 KB |
Output is correct |
11 |
Correct |
70 ms |
15972 KB |
Output is correct |
12 |
Correct |
65 ms |
15868 KB |
Output is correct |
13 |
Correct |
63 ms |
15952 KB |
Output is correct |
14 |
Correct |
107 ms |
15948 KB |
Output is correct |
15 |
Correct |
86 ms |
15852 KB |
Output is correct |
16 |
Correct |
94 ms |
15856 KB |
Output is correct |
17 |
Correct |
85 ms |
15856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
60 ms |
15916 KB |
Output is correct |
3 |
Correct |
59 ms |
15896 KB |
Output is correct |
4 |
Correct |
78 ms |
15868 KB |
Output is correct |
5 |
Correct |
69 ms |
15852 KB |
Output is correct |
6 |
Correct |
70 ms |
15908 KB |
Output is correct |
7 |
Correct |
70 ms |
15852 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
116 ms |
16000 KB |
Output is correct |
11 |
Correct |
70 ms |
15972 KB |
Output is correct |
12 |
Correct |
65 ms |
15868 KB |
Output is correct |
13 |
Correct |
63 ms |
15952 KB |
Output is correct |
14 |
Correct |
107 ms |
15948 KB |
Output is correct |
15 |
Correct |
86 ms |
15852 KB |
Output is correct |
16 |
Correct |
94 ms |
15856 KB |
Output is correct |
17 |
Correct |
85 ms |
15856 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
104 ms |
16744 KB |
Output is correct |
20 |
Correct |
99 ms |
16748 KB |
Output is correct |
21 |
Correct |
98 ms |
16912 KB |
Output is correct |
22 |
Correct |
104 ms |
17172 KB |
Output is correct |
23 |
Correct |
86 ms |
17772 KB |
Output is correct |
24 |
Correct |
86 ms |
17640 KB |
Output is correct |
25 |
Correct |
108 ms |
17520 KB |
Output is correct |
26 |
Correct |
82 ms |
17496 KB |
Output is correct |
27 |
Correct |
92 ms |
17496 KB |
Output is correct |
28 |
Correct |
90 ms |
16236 KB |
Output is correct |
29 |
Correct |
90 ms |
16692 KB |
Output is correct |
30 |
Correct |
93 ms |
17240 KB |
Output is correct |
31 |
Correct |
84 ms |
17484 KB |
Output is correct |
32 |
Correct |
119 ms |
17524 KB |
Output is correct |
33 |
Correct |
94 ms |
18288 KB |
Output is correct |
34 |
Correct |
120 ms |
17072 KB |
Output is correct |
35 |
Correct |
127 ms |
18252 KB |
Output is correct |
36 |
Correct |
92 ms |
18024 KB |
Output is correct |
37 |
Correct |
94 ms |
18028 KB |
Output is correct |
38 |
Correct |
94 ms |
17760 KB |
Output is correct |
39 |
Correct |
86 ms |
17504 KB |
Output is correct |
40 |
Correct |
88 ms |
17892 KB |
Output is correct |
41 |
Correct |
84 ms |
15880 KB |
Output is correct |
42 |
Correct |
82 ms |
15948 KB |
Output is correct |
43 |
Correct |
133 ms |
17132 KB |
Output is correct |
44 |
Correct |
118 ms |
17132 KB |
Output is correct |
45 |
Correct |
100 ms |
17100 KB |
Output is correct |
46 |
Correct |
112 ms |
17084 KB |
Output is correct |
47 |
Correct |
112 ms |
17100 KB |
Output is correct |
48 |
Correct |
104 ms |
17192 KB |
Output is correct |
49 |
Correct |
90 ms |
17148 KB |
Output is correct |
50 |
Correct |
90 ms |
17108 KB |
Output is correct |
51 |
Correct |
102 ms |
17128 KB |
Output is correct |
52 |
Correct |
90 ms |
17108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
60 ms |
15916 KB |
Output is correct |
3 |
Correct |
59 ms |
15896 KB |
Output is correct |
4 |
Correct |
78 ms |
15868 KB |
Output is correct |
5 |
Correct |
69 ms |
15852 KB |
Output is correct |
6 |
Correct |
70 ms |
15908 KB |
Output is correct |
7 |
Correct |
70 ms |
15852 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
116 ms |
16000 KB |
Output is correct |
11 |
Correct |
70 ms |
15972 KB |
Output is correct |
12 |
Correct |
65 ms |
15868 KB |
Output is correct |
13 |
Correct |
63 ms |
15952 KB |
Output is correct |
14 |
Correct |
107 ms |
15948 KB |
Output is correct |
15 |
Correct |
86 ms |
15852 KB |
Output is correct |
16 |
Correct |
94 ms |
15856 KB |
Output is correct |
17 |
Correct |
85 ms |
15856 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
104 ms |
16744 KB |
Output is correct |
20 |
Correct |
99 ms |
16748 KB |
Output is correct |
21 |
Correct |
98 ms |
16912 KB |
Output is correct |
22 |
Correct |
104 ms |
17172 KB |
Output is correct |
23 |
Correct |
86 ms |
17772 KB |
Output is correct |
24 |
Correct |
86 ms |
17640 KB |
Output is correct |
25 |
Correct |
108 ms |
17520 KB |
Output is correct |
26 |
Correct |
82 ms |
17496 KB |
Output is correct |
27 |
Correct |
92 ms |
17496 KB |
Output is correct |
28 |
Correct |
90 ms |
16236 KB |
Output is correct |
29 |
Correct |
90 ms |
16692 KB |
Output is correct |
30 |
Correct |
93 ms |
17240 KB |
Output is correct |
31 |
Correct |
84 ms |
17484 KB |
Output is correct |
32 |
Correct |
119 ms |
17524 KB |
Output is correct |
33 |
Correct |
94 ms |
18288 KB |
Output is correct |
34 |
Correct |
120 ms |
17072 KB |
Output is correct |
35 |
Correct |
127 ms |
18252 KB |
Output is correct |
36 |
Correct |
92 ms |
18024 KB |
Output is correct |
37 |
Correct |
94 ms |
18028 KB |
Output is correct |
38 |
Correct |
94 ms |
17760 KB |
Output is correct |
39 |
Correct |
86 ms |
17504 KB |
Output is correct |
40 |
Correct |
88 ms |
17892 KB |
Output is correct |
41 |
Correct |
84 ms |
15880 KB |
Output is correct |
42 |
Correct |
82 ms |
15948 KB |
Output is correct |
43 |
Correct |
133 ms |
17132 KB |
Output is correct |
44 |
Correct |
118 ms |
17132 KB |
Output is correct |
45 |
Correct |
100 ms |
17100 KB |
Output is correct |
46 |
Correct |
112 ms |
17084 KB |
Output is correct |
47 |
Correct |
112 ms |
17100 KB |
Output is correct |
48 |
Correct |
104 ms |
17192 KB |
Output is correct |
49 |
Correct |
90 ms |
17148 KB |
Output is correct |
50 |
Correct |
90 ms |
17108 KB |
Output is correct |
51 |
Correct |
102 ms |
17128 KB |
Output is correct |
52 |
Correct |
90 ms |
17108 KB |
Output is correct |
53 |
Correct |
3 ms |
4948 KB |
Output is correct |
54 |
Correct |
116 ms |
17288 KB |
Output is correct |
55 |
Correct |
117 ms |
17224 KB |
Output is correct |
56 |
Correct |
154 ms |
18116 KB |
Output is correct |
57 |
Correct |
163 ms |
19968 KB |
Output is correct |
58 |
Correct |
178 ms |
20532 KB |
Output is correct |
59 |
Correct |
165 ms |
20568 KB |
Output is correct |
60 |
Correct |
118 ms |
19024 KB |
Output is correct |
61 |
Correct |
151 ms |
20348 KB |
Output is correct |
62 |
Correct |
151 ms |
20440 KB |
Output is correct |
63 |
Correct |
115 ms |
16788 KB |
Output is correct |
64 |
Correct |
134 ms |
18196 KB |
Output is correct |
65 |
Correct |
151 ms |
19948 KB |
Output is correct |
66 |
Correct |
152 ms |
20292 KB |
Output is correct |
67 |
Correct |
158 ms |
20364 KB |
Output is correct |
68 |
Correct |
101 ms |
18680 KB |
Output is correct |
69 |
Correct |
138 ms |
19008 KB |
Output is correct |
70 |
Correct |
107 ms |
18800 KB |
Output is correct |
71 |
Correct |
97 ms |
18356 KB |
Output is correct |
72 |
Correct |
108 ms |
18408 KB |
Output is correct |
73 |
Correct |
99 ms |
18024 KB |
Output is correct |
74 |
Correct |
89 ms |
17796 KB |
Output is correct |
75 |
Correct |
92 ms |
18244 KB |
Output is correct |
76 |
Correct |
91 ms |
16264 KB |
Output is correct |
77 |
Correct |
84 ms |
16100 KB |
Output is correct |
78 |
Correct |
107 ms |
17580 KB |
Output is correct |
79 |
Correct |
180 ms |
19968 KB |
Output is correct |
80 |
Correct |
142 ms |
18084 KB |
Output is correct |
81 |
Correct |
153 ms |
19464 KB |
Output is correct |
82 |
Correct |
172 ms |
20004 KB |
Output is correct |
83 |
Correct |
177 ms |
20012 KB |
Output is correct |
84 |
Correct |
155 ms |
19976 KB |
Output is correct |
85 |
Correct |
94 ms |
17440 KB |
Output is correct |
86 |
Correct |
111 ms |
17504 KB |
Output is correct |
87 |
Correct |
94 ms |
17424 KB |
Output is correct |
88 |
Correct |
163 ms |
20052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
57 ms |
146336 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
49 ms |
146368 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
64 ms |
150348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
57 ms |
146336 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
49 ms |
146368 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
64 ms |
150348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
60 ms |
15916 KB |
Output is correct |
3 |
Correct |
59 ms |
15896 KB |
Output is correct |
4 |
Correct |
78 ms |
15868 KB |
Output is correct |
5 |
Correct |
69 ms |
15852 KB |
Output is correct |
6 |
Correct |
70 ms |
15908 KB |
Output is correct |
7 |
Correct |
70 ms |
15852 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
116 ms |
16000 KB |
Output is correct |
11 |
Correct |
70 ms |
15972 KB |
Output is correct |
12 |
Correct |
65 ms |
15868 KB |
Output is correct |
13 |
Correct |
63 ms |
15952 KB |
Output is correct |
14 |
Correct |
107 ms |
15948 KB |
Output is correct |
15 |
Correct |
86 ms |
15852 KB |
Output is correct |
16 |
Correct |
94 ms |
15856 KB |
Output is correct |
17 |
Correct |
85 ms |
15856 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
104 ms |
16744 KB |
Output is correct |
20 |
Correct |
99 ms |
16748 KB |
Output is correct |
21 |
Correct |
98 ms |
16912 KB |
Output is correct |
22 |
Correct |
104 ms |
17172 KB |
Output is correct |
23 |
Correct |
86 ms |
17772 KB |
Output is correct |
24 |
Correct |
86 ms |
17640 KB |
Output is correct |
25 |
Correct |
108 ms |
17520 KB |
Output is correct |
26 |
Correct |
82 ms |
17496 KB |
Output is correct |
27 |
Correct |
92 ms |
17496 KB |
Output is correct |
28 |
Correct |
90 ms |
16236 KB |
Output is correct |
29 |
Correct |
90 ms |
16692 KB |
Output is correct |
30 |
Correct |
93 ms |
17240 KB |
Output is correct |
31 |
Correct |
84 ms |
17484 KB |
Output is correct |
32 |
Correct |
119 ms |
17524 KB |
Output is correct |
33 |
Correct |
94 ms |
18288 KB |
Output is correct |
34 |
Correct |
120 ms |
17072 KB |
Output is correct |
35 |
Correct |
127 ms |
18252 KB |
Output is correct |
36 |
Correct |
92 ms |
18024 KB |
Output is correct |
37 |
Correct |
94 ms |
18028 KB |
Output is correct |
38 |
Correct |
94 ms |
17760 KB |
Output is correct |
39 |
Correct |
86 ms |
17504 KB |
Output is correct |
40 |
Correct |
88 ms |
17892 KB |
Output is correct |
41 |
Correct |
84 ms |
15880 KB |
Output is correct |
42 |
Correct |
82 ms |
15948 KB |
Output is correct |
43 |
Correct |
133 ms |
17132 KB |
Output is correct |
44 |
Correct |
118 ms |
17132 KB |
Output is correct |
45 |
Correct |
100 ms |
17100 KB |
Output is correct |
46 |
Correct |
112 ms |
17084 KB |
Output is correct |
47 |
Correct |
112 ms |
17100 KB |
Output is correct |
48 |
Correct |
104 ms |
17192 KB |
Output is correct |
49 |
Correct |
90 ms |
17148 KB |
Output is correct |
50 |
Correct |
90 ms |
17108 KB |
Output is correct |
51 |
Correct |
102 ms |
17128 KB |
Output is correct |
52 |
Correct |
90 ms |
17108 KB |
Output is correct |
53 |
Correct |
3 ms |
4948 KB |
Output is correct |
54 |
Correct |
116 ms |
17288 KB |
Output is correct |
55 |
Correct |
117 ms |
17224 KB |
Output is correct |
56 |
Correct |
154 ms |
18116 KB |
Output is correct |
57 |
Correct |
163 ms |
19968 KB |
Output is correct |
58 |
Correct |
178 ms |
20532 KB |
Output is correct |
59 |
Correct |
165 ms |
20568 KB |
Output is correct |
60 |
Correct |
118 ms |
19024 KB |
Output is correct |
61 |
Correct |
151 ms |
20348 KB |
Output is correct |
62 |
Correct |
151 ms |
20440 KB |
Output is correct |
63 |
Correct |
115 ms |
16788 KB |
Output is correct |
64 |
Correct |
134 ms |
18196 KB |
Output is correct |
65 |
Correct |
151 ms |
19948 KB |
Output is correct |
66 |
Correct |
152 ms |
20292 KB |
Output is correct |
67 |
Correct |
158 ms |
20364 KB |
Output is correct |
68 |
Correct |
101 ms |
18680 KB |
Output is correct |
69 |
Correct |
138 ms |
19008 KB |
Output is correct |
70 |
Correct |
107 ms |
18800 KB |
Output is correct |
71 |
Correct |
97 ms |
18356 KB |
Output is correct |
72 |
Correct |
108 ms |
18408 KB |
Output is correct |
73 |
Correct |
99 ms |
18024 KB |
Output is correct |
74 |
Correct |
89 ms |
17796 KB |
Output is correct |
75 |
Correct |
92 ms |
18244 KB |
Output is correct |
76 |
Correct |
91 ms |
16264 KB |
Output is correct |
77 |
Correct |
84 ms |
16100 KB |
Output is correct |
78 |
Correct |
107 ms |
17580 KB |
Output is correct |
79 |
Correct |
180 ms |
19968 KB |
Output is correct |
80 |
Correct |
142 ms |
18084 KB |
Output is correct |
81 |
Correct |
153 ms |
19464 KB |
Output is correct |
82 |
Correct |
172 ms |
20004 KB |
Output is correct |
83 |
Correct |
177 ms |
20012 KB |
Output is correct |
84 |
Correct |
155 ms |
19976 KB |
Output is correct |
85 |
Correct |
94 ms |
17440 KB |
Output is correct |
86 |
Correct |
111 ms |
17504 KB |
Output is correct |
87 |
Correct |
94 ms |
17424 KB |
Output is correct |
88 |
Correct |
163 ms |
20052 KB |
Output is correct |
89 |
Correct |
2 ms |
4948 KB |
Output is correct |
90 |
Correct |
57 ms |
146336 KB |
Output is correct |
91 |
Correct |
3 ms |
4948 KB |
Output is correct |
92 |
Correct |
2 ms |
4948 KB |
Output is correct |
93 |
Correct |
2 ms |
4948 KB |
Output is correct |
94 |
Correct |
49 ms |
146368 KB |
Output is correct |
95 |
Correct |
2 ms |
4948 KB |
Output is correct |
96 |
Incorrect |
64 ms |
150348 KB |
Output isn't correct |
97 |
Halted |
0 ms |
0 KB |
- |