답안 #1064805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064805 2024-08-18T17:58:10 Z GusterGoose27 Security Guard (JOI23_guard) C++17
50 / 100
120 ms 12384 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5+5;
int n, m, q;

typedef long long ll;
typedef array<int, 2> ar2;

int uf[MAXN];
int val[MAXN];
ar2 edges[2*MAXN];

int find(int i) {
	return uf[i] == i ? i : uf[i] = find(uf[i]);
}

int wt(ar2 i) {
	return val[i[0]] + val[i[1]];
}

struct cmp {
	bool operator()(ar2 i, ar2 j) {
		return ar2({wt(i), i[0]}) < ar2({wt(j), j[0]});
	}
} cmp;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m >> q;
	assert(q == 0);
	iota(uf, uf+n, 0);
	ll s = 0;
	int mx = 0;
	for (int i = 0; i < n; i++) {
		cin >> val[i];
		s -= val[i];
		mx = max(val[i], mx);
	}
	s += mx;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		edges[i] = {a-1, b-1};
	}
	sort(edges, edges+m, cmp);
	for (int i = 0; i < m; i++) {
		int a = find(edges[i][0]);
		int b = find(edges[i][1]);
		int v = wt(edges[i]);
		if (a != b) {
			uf[a] = b;
			s += v;
		}
	}
	cout << s << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 31 ms 6436 KB Output is correct
3 Correct 32 ms 6484 KB Output is correct
4 Correct 42 ms 6488 KB Output is correct
5 Correct 41 ms 6492 KB Output is correct
6 Correct 41 ms 6492 KB Output is correct
7 Correct 43 ms 6456 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 31 ms 6436 KB Output is correct
3 Correct 32 ms 6484 KB Output is correct
4 Correct 42 ms 6488 KB Output is correct
5 Correct 41 ms 6492 KB Output is correct
6 Correct 41 ms 6492 KB Output is correct
7 Correct 43 ms 6456 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 56 ms 7900 KB Output is correct
11 Correct 40 ms 8020 KB Output is correct
12 Correct 38 ms 7804 KB Output is correct
13 Correct 37 ms 8016 KB Output is correct
14 Correct 57 ms 8020 KB Output is correct
15 Correct 58 ms 7952 KB Output is correct
16 Correct 59 ms 8032 KB Output is correct
17 Correct 58 ms 7896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 31 ms 6436 KB Output is correct
3 Correct 32 ms 6484 KB Output is correct
4 Correct 42 ms 6488 KB Output is correct
5 Correct 41 ms 6492 KB Output is correct
6 Correct 41 ms 6492 KB Output is correct
7 Correct 43 ms 6456 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 56 ms 7900 KB Output is correct
11 Correct 40 ms 8020 KB Output is correct
12 Correct 38 ms 7804 KB Output is correct
13 Correct 37 ms 8016 KB Output is correct
14 Correct 57 ms 8020 KB Output is correct
15 Correct 58 ms 7952 KB Output is correct
16 Correct 59 ms 8032 KB Output is correct
17 Correct 58 ms 7896 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 62 ms 7788 KB Output is correct
20 Correct 62 ms 8032 KB Output is correct
21 Correct 61 ms 8020 KB Output is correct
22 Correct 63 ms 8020 KB Output is correct
23 Correct 60 ms 7972 KB Output is correct
24 Correct 59 ms 7852 KB Output is correct
25 Correct 60 ms 8020 KB Output is correct
26 Correct 60 ms 7752 KB Output is correct
27 Correct 57 ms 7780 KB Output is correct
28 Correct 66 ms 8048 KB Output is correct
29 Correct 66 ms 8016 KB Output is correct
30 Correct 59 ms 8020 KB Output is correct
31 Correct 57 ms 8012 KB Output is correct
32 Correct 65 ms 8052 KB Output is correct
33 Correct 66 ms 7184 KB Output is correct
34 Correct 63 ms 7868 KB Output is correct
35 Correct 58 ms 8172 KB Output is correct
36 Correct 51 ms 8148 KB Output is correct
37 Correct 49 ms 8148 KB Output is correct
38 Correct 64 ms 7764 KB Output is correct
39 Correct 56 ms 8276 KB Output is correct
40 Correct 54 ms 8020 KB Output is correct
41 Correct 62 ms 7252 KB Output is correct
42 Correct 56 ms 7252 KB Output is correct
43 Correct 58 ms 7904 KB Output is correct
44 Correct 64 ms 8024 KB Output is correct
45 Correct 60 ms 7884 KB Output is correct
46 Correct 62 ms 8020 KB Output is correct
47 Correct 67 ms 8020 KB Output is correct
48 Correct 74 ms 8052 KB Output is correct
49 Correct 60 ms 8024 KB Output is correct
50 Correct 58 ms 8028 KB Output is correct
51 Correct 55 ms 8020 KB Output is correct
52 Correct 47 ms 6372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 31 ms 6436 KB Output is correct
3 Correct 32 ms 6484 KB Output is correct
4 Correct 42 ms 6488 KB Output is correct
5 Correct 41 ms 6492 KB Output is correct
6 Correct 41 ms 6492 KB Output is correct
7 Correct 43 ms 6456 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 56 ms 7900 KB Output is correct
11 Correct 40 ms 8020 KB Output is correct
12 Correct 38 ms 7804 KB Output is correct
13 Correct 37 ms 8016 KB Output is correct
14 Correct 57 ms 8020 KB Output is correct
15 Correct 58 ms 7952 KB Output is correct
16 Correct 59 ms 8032 KB Output is correct
17 Correct 58 ms 7896 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 62 ms 7788 KB Output is correct
20 Correct 62 ms 8032 KB Output is correct
21 Correct 61 ms 8020 KB Output is correct
22 Correct 63 ms 8020 KB Output is correct
23 Correct 60 ms 7972 KB Output is correct
24 Correct 59 ms 7852 KB Output is correct
25 Correct 60 ms 8020 KB Output is correct
26 Correct 60 ms 7752 KB Output is correct
27 Correct 57 ms 7780 KB Output is correct
28 Correct 66 ms 8048 KB Output is correct
29 Correct 66 ms 8016 KB Output is correct
30 Correct 59 ms 8020 KB Output is correct
31 Correct 57 ms 8012 KB Output is correct
32 Correct 65 ms 8052 KB Output is correct
33 Correct 66 ms 7184 KB Output is correct
34 Correct 63 ms 7868 KB Output is correct
35 Correct 58 ms 8172 KB Output is correct
36 Correct 51 ms 8148 KB Output is correct
37 Correct 49 ms 8148 KB Output is correct
38 Correct 64 ms 7764 KB Output is correct
39 Correct 56 ms 8276 KB Output is correct
40 Correct 54 ms 8020 KB Output is correct
41 Correct 62 ms 7252 KB Output is correct
42 Correct 56 ms 7252 KB Output is correct
43 Correct 58 ms 7904 KB Output is correct
44 Correct 64 ms 8024 KB Output is correct
45 Correct 60 ms 7884 KB Output is correct
46 Correct 62 ms 8020 KB Output is correct
47 Correct 67 ms 8020 KB Output is correct
48 Correct 74 ms 8052 KB Output is correct
49 Correct 60 ms 8024 KB Output is correct
50 Correct 58 ms 8028 KB Output is correct
51 Correct 55 ms 8020 KB Output is correct
52 Correct 47 ms 6372 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 62 ms 8012 KB Output is correct
55 Correct 66 ms 8088 KB Output is correct
56 Correct 76 ms 9296 KB Output is correct
57 Correct 113 ms 12072 KB Output is correct
58 Correct 108 ms 12112 KB Output is correct
59 Correct 113 ms 12384 KB Output is correct
60 Correct 86 ms 9808 KB Output is correct
61 Correct 117 ms 11856 KB Output is correct
62 Correct 109 ms 12112 KB Output is correct
63 Correct 63 ms 8164 KB Output is correct
64 Correct 84 ms 9972 KB Output is correct
65 Correct 112 ms 12112 KB Output is correct
66 Correct 110 ms 11856 KB Output is correct
67 Correct 117 ms 11856 KB Output is correct
68 Correct 58 ms 7336 KB Output is correct
69 Correct 91 ms 10580 KB Output is correct
70 Correct 62 ms 8540 KB Output is correct
71 Correct 50 ms 8016 KB Output is correct
72 Correct 50 ms 8016 KB Output is correct
73 Correct 55 ms 7776 KB Output is correct
74 Correct 52 ms 8276 KB Output is correct
75 Correct 54 ms 7788 KB Output is correct
76 Correct 55 ms 7252 KB Output is correct
77 Correct 56 ms 7252 KB Output is correct
78 Correct 70 ms 8356 KB Output is correct
79 Correct 118 ms 12112 KB Output is correct
80 Correct 72 ms 9040 KB Output is correct
81 Correct 96 ms 11092 KB Output is correct
82 Correct 114 ms 12112 KB Output is correct
83 Correct 120 ms 12116 KB Output is correct
84 Correct 120 ms 11860 KB Output is correct
85 Correct 59 ms 8012 KB Output is correct
86 Correct 55 ms 8248 KB Output is correct
87 Correct 47 ms 6376 KB Output is correct
88 Correct 120 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 31 ms 6436 KB Output is correct
3 Correct 32 ms 6484 KB Output is correct
4 Correct 42 ms 6488 KB Output is correct
5 Correct 41 ms 6492 KB Output is correct
6 Correct 41 ms 6492 KB Output is correct
7 Correct 43 ms 6456 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 56 ms 7900 KB Output is correct
11 Correct 40 ms 8020 KB Output is correct
12 Correct 38 ms 7804 KB Output is correct
13 Correct 37 ms 8016 KB Output is correct
14 Correct 57 ms 8020 KB Output is correct
15 Correct 58 ms 7952 KB Output is correct
16 Correct 59 ms 8032 KB Output is correct
17 Correct 58 ms 7896 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 62 ms 7788 KB Output is correct
20 Correct 62 ms 8032 KB Output is correct
21 Correct 61 ms 8020 KB Output is correct
22 Correct 63 ms 8020 KB Output is correct
23 Correct 60 ms 7972 KB Output is correct
24 Correct 59 ms 7852 KB Output is correct
25 Correct 60 ms 8020 KB Output is correct
26 Correct 60 ms 7752 KB Output is correct
27 Correct 57 ms 7780 KB Output is correct
28 Correct 66 ms 8048 KB Output is correct
29 Correct 66 ms 8016 KB Output is correct
30 Correct 59 ms 8020 KB Output is correct
31 Correct 57 ms 8012 KB Output is correct
32 Correct 65 ms 8052 KB Output is correct
33 Correct 66 ms 7184 KB Output is correct
34 Correct 63 ms 7868 KB Output is correct
35 Correct 58 ms 8172 KB Output is correct
36 Correct 51 ms 8148 KB Output is correct
37 Correct 49 ms 8148 KB Output is correct
38 Correct 64 ms 7764 KB Output is correct
39 Correct 56 ms 8276 KB Output is correct
40 Correct 54 ms 8020 KB Output is correct
41 Correct 62 ms 7252 KB Output is correct
42 Correct 56 ms 7252 KB Output is correct
43 Correct 58 ms 7904 KB Output is correct
44 Correct 64 ms 8024 KB Output is correct
45 Correct 60 ms 7884 KB Output is correct
46 Correct 62 ms 8020 KB Output is correct
47 Correct 67 ms 8020 KB Output is correct
48 Correct 74 ms 8052 KB Output is correct
49 Correct 60 ms 8024 KB Output is correct
50 Correct 58 ms 8028 KB Output is correct
51 Correct 55 ms 8020 KB Output is correct
52 Correct 47 ms 6372 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 62 ms 8012 KB Output is correct
55 Correct 66 ms 8088 KB Output is correct
56 Correct 76 ms 9296 KB Output is correct
57 Correct 113 ms 12072 KB Output is correct
58 Correct 108 ms 12112 KB Output is correct
59 Correct 113 ms 12384 KB Output is correct
60 Correct 86 ms 9808 KB Output is correct
61 Correct 117 ms 11856 KB Output is correct
62 Correct 109 ms 12112 KB Output is correct
63 Correct 63 ms 8164 KB Output is correct
64 Correct 84 ms 9972 KB Output is correct
65 Correct 112 ms 12112 KB Output is correct
66 Correct 110 ms 11856 KB Output is correct
67 Correct 117 ms 11856 KB Output is correct
68 Correct 58 ms 7336 KB Output is correct
69 Correct 91 ms 10580 KB Output is correct
70 Correct 62 ms 8540 KB Output is correct
71 Correct 50 ms 8016 KB Output is correct
72 Correct 50 ms 8016 KB Output is correct
73 Correct 55 ms 7776 KB Output is correct
74 Correct 52 ms 8276 KB Output is correct
75 Correct 54 ms 7788 KB Output is correct
76 Correct 55 ms 7252 KB Output is correct
77 Correct 56 ms 7252 KB Output is correct
78 Correct 70 ms 8356 KB Output is correct
79 Correct 118 ms 12112 KB Output is correct
80 Correct 72 ms 9040 KB Output is correct
81 Correct 96 ms 11092 KB Output is correct
82 Correct 114 ms 12112 KB Output is correct
83 Correct 120 ms 12116 KB Output is correct
84 Correct 120 ms 11860 KB Output is correct
85 Correct 59 ms 8012 KB Output is correct
86 Correct 55 ms 8248 KB Output is correct
87 Correct 47 ms 6376 KB Output is correct
88 Correct 120 ms 12112 KB Output is correct
89 Correct 1 ms 348 KB Output is correct
90 Runtime error 1 ms 604 KB Execution killed with signal 6
91 Halted 0 ms 0 KB -