답안 #796146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796146 2023-07-28T07:03:32 Z 박영우(#10072) Security Guard (JOI23_guard) C++17
50 / 100
158 ms 5804 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<pii> edges;
ll S[MAX];
int vis[MAX];
int p[MAX];
int find(int a) {
	if (p[a] == a) return a;
	return p[a] = find(p[a]);
}
bool uni(int a, int b) {
	a = find(a);
	b = find(b);
	if (a == b) return false;
	p[a] = b;
	return true;
}
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 >> S[i];
	edges.resize(M);
	for (i = 0; i < M; i++) cin >> edges[i].first >> edges[i].second;
	ll ans = 0;
	int mx = 1;
	for (i = 1; i <= N; i++) {
		ans -= S[i];
		if (S[mx] < S[i]) mx = i;
	}
	ans += S[mx];
	for (i = 1; i <= N; i++) p[i] = i;
	sort(edges.begin(), edges.end(), [&](pii p1, pii p2) {return S[p1.first] + S[p1.second] < S[p2.first] + S[p2.second]; });
	for (auto& [a, b] : edges) if (uni(a, b)) ans += S[a] + S[b];
	cout << ans << ln;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 45 ms 4236 KB Output is correct
3 Correct 41 ms 4236 KB Output is correct
4 Correct 43 ms 4244 KB Output is correct
5 Correct 47 ms 4236 KB Output is correct
6 Correct 44 ms 4172 KB Output is correct
7 Correct 43 ms 4228 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 45 ms 4236 KB Output is correct
3 Correct 41 ms 4236 KB Output is correct
4 Correct 43 ms 4244 KB Output is correct
5 Correct 47 ms 4236 KB Output is correct
6 Correct 44 ms 4172 KB Output is correct
7 Correct 43 ms 4228 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 68 ms 4228 KB Output is correct
11 Correct 49 ms 4172 KB Output is correct
12 Correct 52 ms 4220 KB Output is correct
13 Correct 49 ms 4236 KB Output is correct
14 Correct 70 ms 4228 KB Output is correct
15 Correct 70 ms 4232 KB Output is correct
16 Correct 71 ms 4224 KB Output is correct
17 Correct 82 ms 4220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 45 ms 4236 KB Output is correct
3 Correct 41 ms 4236 KB Output is correct
4 Correct 43 ms 4244 KB Output is correct
5 Correct 47 ms 4236 KB Output is correct
6 Correct 44 ms 4172 KB Output is correct
7 Correct 43 ms 4228 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 68 ms 4228 KB Output is correct
11 Correct 49 ms 4172 KB Output is correct
12 Correct 52 ms 4220 KB Output is correct
13 Correct 49 ms 4236 KB Output is correct
14 Correct 70 ms 4228 KB Output is correct
15 Correct 70 ms 4232 KB Output is correct
16 Correct 71 ms 4224 KB Output is correct
17 Correct 82 ms 4220 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 79 ms 4172 KB Output is correct
20 Correct 73 ms 4236 KB Output is correct
21 Correct 75 ms 4216 KB Output is correct
22 Correct 76 ms 4236 KB Output is correct
23 Correct 75 ms 4180 KB Output is correct
24 Correct 73 ms 4172 KB Output is correct
25 Correct 72 ms 4236 KB Output is correct
26 Correct 70 ms 4172 KB Output is correct
27 Correct 69 ms 4120 KB Output is correct
28 Correct 74 ms 4236 KB Output is correct
29 Correct 75 ms 4368 KB Output is correct
30 Correct 72 ms 4372 KB Output is correct
31 Correct 72 ms 4172 KB Output is correct
32 Correct 91 ms 4300 KB Output is correct
33 Correct 56 ms 4172 KB Output is correct
34 Correct 73 ms 4228 KB Output is correct
35 Correct 84 ms 4224 KB Output is correct
36 Correct 61 ms 4220 KB Output is correct
37 Correct 58 ms 4172 KB Output is correct
38 Correct 67 ms 4224 KB Output is correct
39 Correct 63 ms 4860 KB Output is correct
40 Correct 62 ms 4488 KB Output is correct
41 Correct 68 ms 4172 KB Output is correct
42 Correct 69 ms 4228 KB Output is correct
43 Correct 62 ms 4232 KB Output is correct
44 Correct 96 ms 4220 KB Output is correct
45 Correct 95 ms 4224 KB Output is correct
46 Correct 64 ms 4216 KB Output is correct
47 Correct 97 ms 4228 KB Output is correct
48 Correct 72 ms 4160 KB Output is correct
49 Correct 74 ms 4220 KB Output is correct
50 Correct 73 ms 4232 KB Output is correct
51 Correct 74 ms 4200 KB Output is correct
52 Correct 62 ms 4240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 45 ms 4236 KB Output is correct
3 Correct 41 ms 4236 KB Output is correct
4 Correct 43 ms 4244 KB Output is correct
5 Correct 47 ms 4236 KB Output is correct
6 Correct 44 ms 4172 KB Output is correct
7 Correct 43 ms 4228 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 68 ms 4228 KB Output is correct
11 Correct 49 ms 4172 KB Output is correct
12 Correct 52 ms 4220 KB Output is correct
13 Correct 49 ms 4236 KB Output is correct
14 Correct 70 ms 4228 KB Output is correct
15 Correct 70 ms 4232 KB Output is correct
16 Correct 71 ms 4224 KB Output is correct
17 Correct 82 ms 4220 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 79 ms 4172 KB Output is correct
20 Correct 73 ms 4236 KB Output is correct
21 Correct 75 ms 4216 KB Output is correct
22 Correct 76 ms 4236 KB Output is correct
23 Correct 75 ms 4180 KB Output is correct
24 Correct 73 ms 4172 KB Output is correct
25 Correct 72 ms 4236 KB Output is correct
26 Correct 70 ms 4172 KB Output is correct
27 Correct 69 ms 4120 KB Output is correct
28 Correct 74 ms 4236 KB Output is correct
29 Correct 75 ms 4368 KB Output is correct
30 Correct 72 ms 4372 KB Output is correct
31 Correct 72 ms 4172 KB Output is correct
32 Correct 91 ms 4300 KB Output is correct
33 Correct 56 ms 4172 KB Output is correct
34 Correct 73 ms 4228 KB Output is correct
35 Correct 84 ms 4224 KB Output is correct
36 Correct 61 ms 4220 KB Output is correct
37 Correct 58 ms 4172 KB Output is correct
38 Correct 67 ms 4224 KB Output is correct
39 Correct 63 ms 4860 KB Output is correct
40 Correct 62 ms 4488 KB Output is correct
41 Correct 68 ms 4172 KB Output is correct
42 Correct 69 ms 4228 KB Output is correct
43 Correct 62 ms 4232 KB Output is correct
44 Correct 96 ms 4220 KB Output is correct
45 Correct 95 ms 4224 KB Output is correct
46 Correct 64 ms 4216 KB Output is correct
47 Correct 97 ms 4228 KB Output is correct
48 Correct 72 ms 4160 KB Output is correct
49 Correct 74 ms 4220 KB Output is correct
50 Correct 73 ms 4232 KB Output is correct
51 Correct 74 ms 4200 KB Output is correct
52 Correct 62 ms 4240 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 79 ms 4296 KB Output is correct
55 Correct 94 ms 4320 KB Output is correct
56 Correct 107 ms 4712 KB Output is correct
57 Correct 145 ms 5796 KB Output is correct
58 Correct 138 ms 5796 KB Output is correct
59 Correct 135 ms 5708 KB Output is correct
60 Correct 117 ms 4980 KB Output is correct
61 Correct 153 ms 5788 KB Output is correct
62 Correct 154 ms 5804 KB Output is correct
63 Correct 83 ms 4340 KB Output is correct
64 Correct 119 ms 4956 KB Output is correct
65 Correct 158 ms 5788 KB Output is correct
66 Correct 141 ms 5788 KB Output is correct
67 Correct 143 ms 5772 KB Output is correct
68 Correct 80 ms 4220 KB Output is correct
69 Correct 105 ms 5208 KB Output is correct
70 Correct 77 ms 4408 KB Output is correct
71 Correct 60 ms 4172 KB Output is correct
72 Correct 59 ms 4220 KB Output is correct
73 Correct 63 ms 4240 KB Output is correct
74 Correct 63 ms 4876 KB Output is correct
75 Correct 63 ms 4484 KB Output is correct
76 Correct 82 ms 4224 KB Output is correct
77 Correct 72 ms 4232 KB Output is correct
78 Correct 64 ms 4348 KB Output is correct
79 Correct 138 ms 5804 KB Output is correct
80 Correct 81 ms 4648 KB Output is correct
81 Correct 99 ms 5396 KB Output is correct
82 Correct 114 ms 5708 KB Output is correct
83 Correct 121 ms 5784 KB Output is correct
84 Correct 141 ms 5788 KB Output is correct
85 Correct 72 ms 4172 KB Output is correct
86 Correct 75 ms 4328 KB Output is correct
87 Correct 59 ms 4216 KB Output is correct
88 Correct 143 ms 5788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 45 ms 4236 KB Output is correct
3 Correct 41 ms 4236 KB Output is correct
4 Correct 43 ms 4244 KB Output is correct
5 Correct 47 ms 4236 KB Output is correct
6 Correct 44 ms 4172 KB Output is correct
7 Correct 43 ms 4228 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 68 ms 4228 KB Output is correct
11 Correct 49 ms 4172 KB Output is correct
12 Correct 52 ms 4220 KB Output is correct
13 Correct 49 ms 4236 KB Output is correct
14 Correct 70 ms 4228 KB Output is correct
15 Correct 70 ms 4232 KB Output is correct
16 Correct 71 ms 4224 KB Output is correct
17 Correct 82 ms 4220 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 79 ms 4172 KB Output is correct
20 Correct 73 ms 4236 KB Output is correct
21 Correct 75 ms 4216 KB Output is correct
22 Correct 76 ms 4236 KB Output is correct
23 Correct 75 ms 4180 KB Output is correct
24 Correct 73 ms 4172 KB Output is correct
25 Correct 72 ms 4236 KB Output is correct
26 Correct 70 ms 4172 KB Output is correct
27 Correct 69 ms 4120 KB Output is correct
28 Correct 74 ms 4236 KB Output is correct
29 Correct 75 ms 4368 KB Output is correct
30 Correct 72 ms 4372 KB Output is correct
31 Correct 72 ms 4172 KB Output is correct
32 Correct 91 ms 4300 KB Output is correct
33 Correct 56 ms 4172 KB Output is correct
34 Correct 73 ms 4228 KB Output is correct
35 Correct 84 ms 4224 KB Output is correct
36 Correct 61 ms 4220 KB Output is correct
37 Correct 58 ms 4172 KB Output is correct
38 Correct 67 ms 4224 KB Output is correct
39 Correct 63 ms 4860 KB Output is correct
40 Correct 62 ms 4488 KB Output is correct
41 Correct 68 ms 4172 KB Output is correct
42 Correct 69 ms 4228 KB Output is correct
43 Correct 62 ms 4232 KB Output is correct
44 Correct 96 ms 4220 KB Output is correct
45 Correct 95 ms 4224 KB Output is correct
46 Correct 64 ms 4216 KB Output is correct
47 Correct 97 ms 4228 KB Output is correct
48 Correct 72 ms 4160 KB Output is correct
49 Correct 74 ms 4220 KB Output is correct
50 Correct 73 ms 4232 KB Output is correct
51 Correct 74 ms 4200 KB Output is correct
52 Correct 62 ms 4240 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 79 ms 4296 KB Output is correct
55 Correct 94 ms 4320 KB Output is correct
56 Correct 107 ms 4712 KB Output is correct
57 Correct 145 ms 5796 KB Output is correct
58 Correct 138 ms 5796 KB Output is correct
59 Correct 135 ms 5708 KB Output is correct
60 Correct 117 ms 4980 KB Output is correct
61 Correct 153 ms 5788 KB Output is correct
62 Correct 154 ms 5804 KB Output is correct
63 Correct 83 ms 4340 KB Output is correct
64 Correct 119 ms 4956 KB Output is correct
65 Correct 158 ms 5788 KB Output is correct
66 Correct 141 ms 5788 KB Output is correct
67 Correct 143 ms 5772 KB Output is correct
68 Correct 80 ms 4220 KB Output is correct
69 Correct 105 ms 5208 KB Output is correct
70 Correct 77 ms 4408 KB Output is correct
71 Correct 60 ms 4172 KB Output is correct
72 Correct 59 ms 4220 KB Output is correct
73 Correct 63 ms 4240 KB Output is correct
74 Correct 63 ms 4876 KB Output is correct
75 Correct 63 ms 4484 KB Output is correct
76 Correct 82 ms 4224 KB Output is correct
77 Correct 72 ms 4232 KB Output is correct
78 Correct 64 ms 4348 KB Output is correct
79 Correct 138 ms 5804 KB Output is correct
80 Correct 81 ms 4648 KB Output is correct
81 Correct 99 ms 5396 KB Output is correct
82 Correct 114 ms 5708 KB Output is correct
83 Correct 121 ms 5784 KB Output is correct
84 Correct 141 ms 5788 KB Output is correct
85 Correct 72 ms 4172 KB Output is correct
86 Correct 75 ms 4328 KB Output is correct
87 Correct 59 ms 4216 KB Output is correct
88 Correct 143 ms 5788 KB Output is correct
89 Correct 0 ms 212 KB Output is correct
90 Incorrect 0 ms 212 KB Output isn't correct
91 Halted 0 ms 0 KB -