Submission #961047

# Submission time Handle Problem Language Result Execution time Memory
961047 2024-04-11T12:45:59 Z thinknoexit Security Guard (JOI23_guard) C++17
50 / 100
144 ms 18124 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200200;
int a[N];
vector<int> adj[N];
struct A {
    int u, v;
    bool operator < (const A& o) const {
        return a[u] + a[v] < a[o.u] + a[o.v];
    }
};
ll ans = 0;
vector<A> e;
int p[N];
int fr(int i) {
    return p[i] == i ? i : p[i] = fr(p[i]);
}
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
        p[i] = i;
    }
    while (m--) {
        int u, v;
        cin >> u >> v;
        e.push_back({ u, v });
    }
    sort(e.begin(), e.end());
    for (auto& x : e) {
        int u = x.u, v = x.v;
        int pu = fr(u), pv = fr(v);
        if (pu == pv) continue;
        ans += a[u] + a[v];
        p[pu] = pv;
    }
    for (int i = 1;i <= n;i++) ans -= a[i];
    ans += *max_element(a + 1, a + 1 + n);
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5732 KB Output is correct
2 Correct 39 ms 10976 KB Output is correct
3 Correct 39 ms 10932 KB Output is correct
4 Correct 42 ms 10948 KB Output is correct
5 Correct 42 ms 10776 KB Output is correct
6 Correct 43 ms 10772 KB Output is correct
7 Correct 41 ms 10952 KB Output is correct
8 Correct 1 ms 5720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5732 KB Output is correct
2 Correct 39 ms 10976 KB Output is correct
3 Correct 39 ms 10932 KB Output is correct
4 Correct 42 ms 10948 KB Output is correct
5 Correct 42 ms 10776 KB Output is correct
6 Correct 43 ms 10772 KB Output is correct
7 Correct 41 ms 10952 KB Output is correct
8 Correct 1 ms 5720 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 72 ms 12248 KB Output is correct
11 Correct 47 ms 12236 KB Output is correct
12 Correct 46 ms 12188 KB Output is correct
13 Correct 47 ms 11996 KB Output is correct
14 Correct 64 ms 12000 KB Output is correct
15 Correct 65 ms 12252 KB Output is correct
16 Correct 64 ms 12128 KB Output is correct
17 Correct 64 ms 12240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5732 KB Output is correct
2 Correct 39 ms 10976 KB Output is correct
3 Correct 39 ms 10932 KB Output is correct
4 Correct 42 ms 10948 KB Output is correct
5 Correct 42 ms 10776 KB Output is correct
6 Correct 43 ms 10772 KB Output is correct
7 Correct 41 ms 10952 KB Output is correct
8 Correct 1 ms 5720 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 72 ms 12248 KB Output is correct
11 Correct 47 ms 12236 KB Output is correct
12 Correct 46 ms 12188 KB Output is correct
13 Correct 47 ms 11996 KB Output is correct
14 Correct 64 ms 12000 KB Output is correct
15 Correct 65 ms 12252 KB Output is correct
16 Correct 64 ms 12128 KB Output is correct
17 Correct 64 ms 12240 KB Output is correct
18 Correct 2 ms 5720 KB Output is correct
19 Correct 70 ms 12236 KB Output is correct
20 Correct 67 ms 12236 KB Output is correct
21 Correct 68 ms 12232 KB Output is correct
22 Correct 73 ms 12240 KB Output is correct
23 Correct 73 ms 12156 KB Output is correct
24 Correct 67 ms 12224 KB Output is correct
25 Correct 66 ms 12240 KB Output is correct
26 Correct 66 ms 12260 KB Output is correct
27 Correct 75 ms 12244 KB Output is correct
28 Correct 68 ms 12492 KB Output is correct
29 Correct 66 ms 12236 KB Output is correct
30 Correct 68 ms 12352 KB Output is correct
31 Correct 66 ms 12240 KB Output is correct
32 Correct 74 ms 12248 KB Output is correct
33 Correct 50 ms 11472 KB Output is correct
34 Correct 64 ms 12240 KB Output is correct
35 Correct 62 ms 12192 KB Output is correct
36 Correct 54 ms 12492 KB Output is correct
37 Correct 62 ms 12492 KB Output is correct
38 Correct 58 ms 12244 KB Output is correct
39 Correct 59 ms 12512 KB Output is correct
40 Correct 58 ms 11996 KB Output is correct
41 Correct 64 ms 11872 KB Output is correct
42 Correct 63 ms 11560 KB Output is correct
43 Correct 62 ms 12260 KB Output is correct
44 Correct 70 ms 12128 KB Output is correct
45 Correct 59 ms 12300 KB Output is correct
46 Correct 76 ms 12492 KB Output is correct
47 Correct 62 ms 12524 KB Output is correct
48 Correct 64 ms 12496 KB Output is correct
49 Correct 68 ms 12496 KB Output is correct
50 Correct 70 ms 12236 KB Output is correct
51 Correct 62 ms 12620 KB Output is correct
52 Correct 49 ms 10916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5732 KB Output is correct
2 Correct 39 ms 10976 KB Output is correct
3 Correct 39 ms 10932 KB Output is correct
4 Correct 42 ms 10948 KB Output is correct
5 Correct 42 ms 10776 KB Output is correct
6 Correct 43 ms 10772 KB Output is correct
7 Correct 41 ms 10952 KB Output is correct
8 Correct 1 ms 5720 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 72 ms 12248 KB Output is correct
11 Correct 47 ms 12236 KB Output is correct
12 Correct 46 ms 12188 KB Output is correct
13 Correct 47 ms 11996 KB Output is correct
14 Correct 64 ms 12000 KB Output is correct
15 Correct 65 ms 12252 KB Output is correct
16 Correct 64 ms 12128 KB Output is correct
17 Correct 64 ms 12240 KB Output is correct
18 Correct 2 ms 5720 KB Output is correct
19 Correct 70 ms 12236 KB Output is correct
20 Correct 67 ms 12236 KB Output is correct
21 Correct 68 ms 12232 KB Output is correct
22 Correct 73 ms 12240 KB Output is correct
23 Correct 73 ms 12156 KB Output is correct
24 Correct 67 ms 12224 KB Output is correct
25 Correct 66 ms 12240 KB Output is correct
26 Correct 66 ms 12260 KB Output is correct
27 Correct 75 ms 12244 KB Output is correct
28 Correct 68 ms 12492 KB Output is correct
29 Correct 66 ms 12236 KB Output is correct
30 Correct 68 ms 12352 KB Output is correct
31 Correct 66 ms 12240 KB Output is correct
32 Correct 74 ms 12248 KB Output is correct
33 Correct 50 ms 11472 KB Output is correct
34 Correct 64 ms 12240 KB Output is correct
35 Correct 62 ms 12192 KB Output is correct
36 Correct 54 ms 12492 KB Output is correct
37 Correct 62 ms 12492 KB Output is correct
38 Correct 58 ms 12244 KB Output is correct
39 Correct 59 ms 12512 KB Output is correct
40 Correct 58 ms 11996 KB Output is correct
41 Correct 64 ms 11872 KB Output is correct
42 Correct 63 ms 11560 KB Output is correct
43 Correct 62 ms 12260 KB Output is correct
44 Correct 70 ms 12128 KB Output is correct
45 Correct 59 ms 12300 KB Output is correct
46 Correct 76 ms 12492 KB Output is correct
47 Correct 62 ms 12524 KB Output is correct
48 Correct 64 ms 12496 KB Output is correct
49 Correct 68 ms 12496 KB Output is correct
50 Correct 70 ms 12236 KB Output is correct
51 Correct 62 ms 12620 KB Output is correct
52 Correct 49 ms 10916 KB Output is correct
53 Correct 2 ms 5976 KB Output is correct
54 Correct 75 ms 12496 KB Output is correct
55 Correct 71 ms 13000 KB Output is correct
56 Correct 90 ms 17412 KB Output is correct
57 Correct 129 ms 17796 KB Output is correct
58 Correct 126 ms 16944 KB Output is correct
59 Correct 130 ms 16844 KB Output is correct
60 Correct 96 ms 18116 KB Output is correct
61 Correct 132 ms 17868 KB Output is correct
62 Correct 131 ms 17892 KB Output is correct
63 Correct 80 ms 12992 KB Output is correct
64 Correct 113 ms 17868 KB Output is correct
65 Correct 128 ms 16896 KB Output is correct
66 Correct 120 ms 16688 KB Output is correct
67 Correct 130 ms 16836 KB Output is correct
68 Correct 52 ms 11824 KB Output is correct
69 Correct 109 ms 16840 KB Output is correct
70 Correct 71 ms 13320 KB Output is correct
71 Correct 58 ms 12920 KB Output is correct
72 Correct 57 ms 13056 KB Output is correct
73 Correct 75 ms 12748 KB Output is correct
74 Correct 60 ms 13000 KB Output is correct
75 Correct 62 ms 12624 KB Output is correct
76 Correct 65 ms 12080 KB Output is correct
77 Correct 62 ms 11984 KB Output is correct
78 Correct 59 ms 13000 KB Output is correct
79 Correct 144 ms 16724 KB Output is correct
80 Correct 69 ms 14024 KB Output is correct
81 Correct 90 ms 17528 KB Output is correct
82 Correct 106 ms 17908 KB Output is correct
83 Correct 119 ms 17968 KB Output is correct
84 Correct 129 ms 17864 KB Output is correct
85 Correct 71 ms 12744 KB Output is correct
86 Correct 60 ms 13064 KB Output is correct
87 Correct 46 ms 11220 KB Output is correct
88 Correct 141 ms 18124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5720 KB Output is correct
2 Incorrect 1 ms 5768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5720 KB Output is correct
2 Incorrect 1 ms 5768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5732 KB Output is correct
2 Correct 39 ms 10976 KB Output is correct
3 Correct 39 ms 10932 KB Output is correct
4 Correct 42 ms 10948 KB Output is correct
5 Correct 42 ms 10776 KB Output is correct
6 Correct 43 ms 10772 KB Output is correct
7 Correct 41 ms 10952 KB Output is correct
8 Correct 1 ms 5720 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 72 ms 12248 KB Output is correct
11 Correct 47 ms 12236 KB Output is correct
12 Correct 46 ms 12188 KB Output is correct
13 Correct 47 ms 11996 KB Output is correct
14 Correct 64 ms 12000 KB Output is correct
15 Correct 65 ms 12252 KB Output is correct
16 Correct 64 ms 12128 KB Output is correct
17 Correct 64 ms 12240 KB Output is correct
18 Correct 2 ms 5720 KB Output is correct
19 Correct 70 ms 12236 KB Output is correct
20 Correct 67 ms 12236 KB Output is correct
21 Correct 68 ms 12232 KB Output is correct
22 Correct 73 ms 12240 KB Output is correct
23 Correct 73 ms 12156 KB Output is correct
24 Correct 67 ms 12224 KB Output is correct
25 Correct 66 ms 12240 KB Output is correct
26 Correct 66 ms 12260 KB Output is correct
27 Correct 75 ms 12244 KB Output is correct
28 Correct 68 ms 12492 KB Output is correct
29 Correct 66 ms 12236 KB Output is correct
30 Correct 68 ms 12352 KB Output is correct
31 Correct 66 ms 12240 KB Output is correct
32 Correct 74 ms 12248 KB Output is correct
33 Correct 50 ms 11472 KB Output is correct
34 Correct 64 ms 12240 KB Output is correct
35 Correct 62 ms 12192 KB Output is correct
36 Correct 54 ms 12492 KB Output is correct
37 Correct 62 ms 12492 KB Output is correct
38 Correct 58 ms 12244 KB Output is correct
39 Correct 59 ms 12512 KB Output is correct
40 Correct 58 ms 11996 KB Output is correct
41 Correct 64 ms 11872 KB Output is correct
42 Correct 63 ms 11560 KB Output is correct
43 Correct 62 ms 12260 KB Output is correct
44 Correct 70 ms 12128 KB Output is correct
45 Correct 59 ms 12300 KB Output is correct
46 Correct 76 ms 12492 KB Output is correct
47 Correct 62 ms 12524 KB Output is correct
48 Correct 64 ms 12496 KB Output is correct
49 Correct 68 ms 12496 KB Output is correct
50 Correct 70 ms 12236 KB Output is correct
51 Correct 62 ms 12620 KB Output is correct
52 Correct 49 ms 10916 KB Output is correct
53 Correct 2 ms 5976 KB Output is correct
54 Correct 75 ms 12496 KB Output is correct
55 Correct 71 ms 13000 KB Output is correct
56 Correct 90 ms 17412 KB Output is correct
57 Correct 129 ms 17796 KB Output is correct
58 Correct 126 ms 16944 KB Output is correct
59 Correct 130 ms 16844 KB Output is correct
60 Correct 96 ms 18116 KB Output is correct
61 Correct 132 ms 17868 KB Output is correct
62 Correct 131 ms 17892 KB Output is correct
63 Correct 80 ms 12992 KB Output is correct
64 Correct 113 ms 17868 KB Output is correct
65 Correct 128 ms 16896 KB Output is correct
66 Correct 120 ms 16688 KB Output is correct
67 Correct 130 ms 16836 KB Output is correct
68 Correct 52 ms 11824 KB Output is correct
69 Correct 109 ms 16840 KB Output is correct
70 Correct 71 ms 13320 KB Output is correct
71 Correct 58 ms 12920 KB Output is correct
72 Correct 57 ms 13056 KB Output is correct
73 Correct 75 ms 12748 KB Output is correct
74 Correct 60 ms 13000 KB Output is correct
75 Correct 62 ms 12624 KB Output is correct
76 Correct 65 ms 12080 KB Output is correct
77 Correct 62 ms 11984 KB Output is correct
78 Correct 59 ms 13000 KB Output is correct
79 Correct 144 ms 16724 KB Output is correct
80 Correct 69 ms 14024 KB Output is correct
81 Correct 90 ms 17528 KB Output is correct
82 Correct 106 ms 17908 KB Output is correct
83 Correct 119 ms 17968 KB Output is correct
84 Correct 129 ms 17864 KB Output is correct
85 Correct 71 ms 12744 KB Output is correct
86 Correct 60 ms 13064 KB Output is correct
87 Correct 46 ms 11220 KB Output is correct
88 Correct 141 ms 18124 KB Output is correct
89 Correct 1 ms 5720 KB Output is correct
90 Incorrect 1 ms 5768 KB Output isn't correct
91 Halted 0 ms 0 KB -