답안 #796202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796202 2023-07-28T07:46:48 Z 이성호(#10070) Security Guard (JOI23_guard) C++17
50 / 100
144 ms 17628 KB
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
vector<int> adj[200005];
pair<int, pair<int, int>> edge[400005];
int S[200005];
int N, M, Q;
struct UnionFind
{
    vector<int> par;
    UnionFind(int n){par.resize(n+1); for(int i=1;i<=n;i++) par[i] = i;}
    int fin(int i){return i==par[i]?i:(par[i] = fin(par[i]));}
    void uni(int u, int v){par[fin(u)] = fin(v);}
    bool isuni(int u, int v){return fin(u) == fin(v);}
};
signed main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> N >> M >> Q;
    for (int i = 1; i <= N; i++) cin >> S[i];
    for (int i = 0; i < M; i++) {
        int u, v; cin >> u >> v;
        edge[i] = make_pair(S[u] + S[v], make_pair(u, v));
    }
    int ans = 0;
    sort(edge, edge + M);
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int u = edge[i].second.first, v = edge[i].second.second;
        if (!uf.isuni(u, v)) {
            uf.uni(u, v);
            ans += S[u] + S[v];
        }
    }
    cout << ans + *max_element(S+1, S+N+1) - accumulate(S+1, S+N+1, 0LL) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 40 ms 12776 KB Output is correct
3 Correct 40 ms 12764 KB Output is correct
4 Correct 51 ms 12832 KB Output is correct
5 Correct 50 ms 12768 KB Output is correct
6 Correct 48 ms 12800 KB Output is correct
7 Correct 53 ms 12744 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 40 ms 12776 KB Output is correct
3 Correct 40 ms 12764 KB Output is correct
4 Correct 51 ms 12832 KB Output is correct
5 Correct 50 ms 12768 KB Output is correct
6 Correct 48 ms 12800 KB Output is correct
7 Correct 53 ms 12744 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 63 ms 12828 KB Output is correct
11 Correct 47 ms 12800 KB Output is correct
12 Correct 45 ms 12748 KB Output is correct
13 Correct 45 ms 12836 KB Output is correct
14 Correct 60 ms 12748 KB Output is correct
15 Correct 59 ms 12812 KB Output is correct
16 Correct 63 ms 12804 KB Output is correct
17 Correct 69 ms 12828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 40 ms 12776 KB Output is correct
3 Correct 40 ms 12764 KB Output is correct
4 Correct 51 ms 12832 KB Output is correct
5 Correct 50 ms 12768 KB Output is correct
6 Correct 48 ms 12800 KB Output is correct
7 Correct 53 ms 12744 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 63 ms 12828 KB Output is correct
11 Correct 47 ms 12800 KB Output is correct
12 Correct 45 ms 12748 KB Output is correct
13 Correct 45 ms 12836 KB Output is correct
14 Correct 60 ms 12748 KB Output is correct
15 Correct 59 ms 12812 KB Output is correct
16 Correct 63 ms 12804 KB Output is correct
17 Correct 69 ms 12828 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 63 ms 12780 KB Output is correct
20 Correct 63 ms 12728 KB Output is correct
21 Correct 64 ms 12768 KB Output is correct
22 Correct 82 ms 12800 KB Output is correct
23 Correct 64 ms 12844 KB Output is correct
24 Correct 64 ms 12836 KB Output is correct
25 Correct 62 ms 12808 KB Output is correct
26 Correct 63 ms 12804 KB Output is correct
27 Correct 60 ms 12748 KB Output is correct
28 Correct 62 ms 12800 KB Output is correct
29 Correct 64 ms 12912 KB Output is correct
30 Correct 63 ms 12996 KB Output is correct
31 Correct 68 ms 12920 KB Output is correct
32 Correct 81 ms 12756 KB Output is correct
33 Correct 63 ms 12804 KB Output is correct
34 Correct 67 ms 12820 KB Output is correct
35 Correct 69 ms 12748 KB Output is correct
36 Correct 67 ms 12736 KB Output is correct
37 Correct 71 ms 12792 KB Output is correct
38 Correct 63 ms 12784 KB Output is correct
39 Correct 64 ms 13316 KB Output is correct
40 Correct 65 ms 13060 KB Output is correct
41 Correct 63 ms 12800 KB Output is correct
42 Correct 59 ms 12804 KB Output is correct
43 Correct 70 ms 12732 KB Output is correct
44 Correct 83 ms 12752 KB Output is correct
45 Correct 70 ms 12800 KB Output is correct
46 Correct 69 ms 12740 KB Output is correct
47 Correct 91 ms 12740 KB Output is correct
48 Correct 69 ms 12804 KB Output is correct
49 Correct 63 ms 12808 KB Output is correct
50 Correct 66 ms 12804 KB Output is correct
51 Correct 82 ms 12780 KB Output is correct
52 Correct 59 ms 12800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 40 ms 12776 KB Output is correct
3 Correct 40 ms 12764 KB Output is correct
4 Correct 51 ms 12832 KB Output is correct
5 Correct 50 ms 12768 KB Output is correct
6 Correct 48 ms 12800 KB Output is correct
7 Correct 53 ms 12744 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 63 ms 12828 KB Output is correct
11 Correct 47 ms 12800 KB Output is correct
12 Correct 45 ms 12748 KB Output is correct
13 Correct 45 ms 12836 KB Output is correct
14 Correct 60 ms 12748 KB Output is correct
15 Correct 59 ms 12812 KB Output is correct
16 Correct 63 ms 12804 KB Output is correct
17 Correct 69 ms 12828 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 63 ms 12780 KB Output is correct
20 Correct 63 ms 12728 KB Output is correct
21 Correct 64 ms 12768 KB Output is correct
22 Correct 82 ms 12800 KB Output is correct
23 Correct 64 ms 12844 KB Output is correct
24 Correct 64 ms 12836 KB Output is correct
25 Correct 62 ms 12808 KB Output is correct
26 Correct 63 ms 12804 KB Output is correct
27 Correct 60 ms 12748 KB Output is correct
28 Correct 62 ms 12800 KB Output is correct
29 Correct 64 ms 12912 KB Output is correct
30 Correct 63 ms 12996 KB Output is correct
31 Correct 68 ms 12920 KB Output is correct
32 Correct 81 ms 12756 KB Output is correct
33 Correct 63 ms 12804 KB Output is correct
34 Correct 67 ms 12820 KB Output is correct
35 Correct 69 ms 12748 KB Output is correct
36 Correct 67 ms 12736 KB Output is correct
37 Correct 71 ms 12792 KB Output is correct
38 Correct 63 ms 12784 KB Output is correct
39 Correct 64 ms 13316 KB Output is correct
40 Correct 65 ms 13060 KB Output is correct
41 Correct 63 ms 12800 KB Output is correct
42 Correct 59 ms 12804 KB Output is correct
43 Correct 70 ms 12732 KB Output is correct
44 Correct 83 ms 12752 KB Output is correct
45 Correct 70 ms 12800 KB Output is correct
46 Correct 69 ms 12740 KB Output is correct
47 Correct 91 ms 12740 KB Output is correct
48 Correct 69 ms 12804 KB Output is correct
49 Correct 63 ms 12808 KB Output is correct
50 Correct 66 ms 12804 KB Output is correct
51 Correct 82 ms 12780 KB Output is correct
52 Correct 59 ms 12800 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 66 ms 13044 KB Output is correct
55 Correct 87 ms 13040 KB Output is correct
56 Correct 104 ms 14192 KB Output is correct
57 Correct 116 ms 17408 KB Output is correct
58 Correct 116 ms 17496 KB Output is correct
59 Correct 121 ms 17480 KB Output is correct
60 Correct 89 ms 15076 KB Output is correct
61 Correct 128 ms 17516 KB Output is correct
62 Correct 118 ms 17484 KB Output is correct
63 Correct 68 ms 13120 KB Output is correct
64 Correct 88 ms 15020 KB Output is correct
65 Correct 117 ms 17628 KB Output is correct
66 Correct 123 ms 17472 KB Output is correct
67 Correct 124 ms 17420 KB Output is correct
68 Correct 63 ms 12748 KB Output is correct
69 Correct 104 ms 15752 KB Output is correct
70 Correct 76 ms 13364 KB Output is correct
71 Correct 68 ms 12748 KB Output is correct
72 Correct 67 ms 12776 KB Output is correct
73 Correct 68 ms 12792 KB Output is correct
74 Correct 86 ms 13312 KB Output is correct
75 Correct 70 ms 12984 KB Output is correct
76 Correct 62 ms 12784 KB Output is correct
77 Correct 62 ms 12800 KB Output is correct
78 Correct 79 ms 13140 KB Output is correct
79 Correct 136 ms 17452 KB Output is correct
80 Correct 85 ms 13996 KB Output is correct
81 Correct 144 ms 16472 KB Output is correct
82 Correct 123 ms 17440 KB Output is correct
83 Correct 126 ms 17428 KB Output is correct
84 Correct 120 ms 17468 KB Output is correct
85 Correct 64 ms 12804 KB Output is correct
86 Correct 70 ms 12784 KB Output is correct
87 Correct 64 ms 12740 KB Output is correct
88 Correct 124 ms 17492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 40 ms 12776 KB Output is correct
3 Correct 40 ms 12764 KB Output is correct
4 Correct 51 ms 12832 KB Output is correct
5 Correct 50 ms 12768 KB Output is correct
6 Correct 48 ms 12800 KB Output is correct
7 Correct 53 ms 12744 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 63 ms 12828 KB Output is correct
11 Correct 47 ms 12800 KB Output is correct
12 Correct 45 ms 12748 KB Output is correct
13 Correct 45 ms 12836 KB Output is correct
14 Correct 60 ms 12748 KB Output is correct
15 Correct 59 ms 12812 KB Output is correct
16 Correct 63 ms 12804 KB Output is correct
17 Correct 69 ms 12828 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 63 ms 12780 KB Output is correct
20 Correct 63 ms 12728 KB Output is correct
21 Correct 64 ms 12768 KB Output is correct
22 Correct 82 ms 12800 KB Output is correct
23 Correct 64 ms 12844 KB Output is correct
24 Correct 64 ms 12836 KB Output is correct
25 Correct 62 ms 12808 KB Output is correct
26 Correct 63 ms 12804 KB Output is correct
27 Correct 60 ms 12748 KB Output is correct
28 Correct 62 ms 12800 KB Output is correct
29 Correct 64 ms 12912 KB Output is correct
30 Correct 63 ms 12996 KB Output is correct
31 Correct 68 ms 12920 KB Output is correct
32 Correct 81 ms 12756 KB Output is correct
33 Correct 63 ms 12804 KB Output is correct
34 Correct 67 ms 12820 KB Output is correct
35 Correct 69 ms 12748 KB Output is correct
36 Correct 67 ms 12736 KB Output is correct
37 Correct 71 ms 12792 KB Output is correct
38 Correct 63 ms 12784 KB Output is correct
39 Correct 64 ms 13316 KB Output is correct
40 Correct 65 ms 13060 KB Output is correct
41 Correct 63 ms 12800 KB Output is correct
42 Correct 59 ms 12804 KB Output is correct
43 Correct 70 ms 12732 KB Output is correct
44 Correct 83 ms 12752 KB Output is correct
45 Correct 70 ms 12800 KB Output is correct
46 Correct 69 ms 12740 KB Output is correct
47 Correct 91 ms 12740 KB Output is correct
48 Correct 69 ms 12804 KB Output is correct
49 Correct 63 ms 12808 KB Output is correct
50 Correct 66 ms 12804 KB Output is correct
51 Correct 82 ms 12780 KB Output is correct
52 Correct 59 ms 12800 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 66 ms 13044 KB Output is correct
55 Correct 87 ms 13040 KB Output is correct
56 Correct 104 ms 14192 KB Output is correct
57 Correct 116 ms 17408 KB Output is correct
58 Correct 116 ms 17496 KB Output is correct
59 Correct 121 ms 17480 KB Output is correct
60 Correct 89 ms 15076 KB Output is correct
61 Correct 128 ms 17516 KB Output is correct
62 Correct 118 ms 17484 KB Output is correct
63 Correct 68 ms 13120 KB Output is correct
64 Correct 88 ms 15020 KB Output is correct
65 Correct 117 ms 17628 KB Output is correct
66 Correct 123 ms 17472 KB Output is correct
67 Correct 124 ms 17420 KB Output is correct
68 Correct 63 ms 12748 KB Output is correct
69 Correct 104 ms 15752 KB Output is correct
70 Correct 76 ms 13364 KB Output is correct
71 Correct 68 ms 12748 KB Output is correct
72 Correct 67 ms 12776 KB Output is correct
73 Correct 68 ms 12792 KB Output is correct
74 Correct 86 ms 13312 KB Output is correct
75 Correct 70 ms 12984 KB Output is correct
76 Correct 62 ms 12784 KB Output is correct
77 Correct 62 ms 12800 KB Output is correct
78 Correct 79 ms 13140 KB Output is correct
79 Correct 136 ms 17452 KB Output is correct
80 Correct 85 ms 13996 KB Output is correct
81 Correct 144 ms 16472 KB Output is correct
82 Correct 123 ms 17440 KB Output is correct
83 Correct 126 ms 17428 KB Output is correct
84 Correct 120 ms 17468 KB Output is correct
85 Correct 64 ms 12804 KB Output is correct
86 Correct 70 ms 12784 KB Output is correct
87 Correct 64 ms 12740 KB Output is correct
88 Correct 124 ms 17492 KB Output is correct
89 Correct 2 ms 4948 KB Output is correct
90 Incorrect 2 ms 4948 KB Output isn't correct
91 Halted 0 ms 0 KB -