Submission #960990

# Submission time Handle Problem Language Result Execution time Memory
960990 2024-04-11T10:40:46 Z thinknoexit Security Guard (JOI23_guard) C++17
37 / 100
129 ms 25648 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 {
        if (a[u] != a[o.u]) return a[u] < a[o.u];
        return a[v] < 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]);
}
void dfs(int v, int p = -1) {
    for (auto& x : adj[v]) {
        if (x == p) continue;
        ans += a[v];
        dfs(x, v);
    }
}
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;
        if (a[v] > a[u]) swap(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;
        adj[u].push_back(v);
        adj[v].push_back(u);
        p[pu] = pv;
    }
    int idx = max_element(a + 1, a + 1 + n) - a;
    dfs(idx);
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5724 KB Output is correct
2 Correct 63 ms 23864 KB Output is correct
3 Correct 67 ms 24008 KB Output is correct
4 Correct 76 ms 24008 KB Output is correct
5 Correct 76 ms 23948 KB Output is correct
6 Correct 72 ms 23856 KB Output is correct
7 Correct 70 ms 23944 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5724 KB Output is correct
2 Correct 63 ms 23864 KB Output is correct
3 Correct 67 ms 24008 KB Output is correct
4 Correct 76 ms 24008 KB Output is correct
5 Correct 76 ms 23948 KB Output is correct
6 Correct 72 ms 23856 KB Output is correct
7 Correct 70 ms 23944 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5720 KB Output is correct
10 Correct 115 ms 23108 KB Output is correct
11 Correct 68 ms 25648 KB Output is correct
12 Correct 61 ms 25516 KB Output is correct
13 Correct 64 ms 25544 KB Output is correct
14 Correct 99 ms 25536 KB Output is correct
15 Correct 111 ms 25464 KB Output is correct
16 Correct 90 ms 24644 KB Output is correct
17 Correct 90 ms 25108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5724 KB Output is correct
2 Correct 63 ms 23864 KB Output is correct
3 Correct 67 ms 24008 KB Output is correct
4 Correct 76 ms 24008 KB Output is correct
5 Correct 76 ms 23948 KB Output is correct
6 Correct 72 ms 23856 KB Output is correct
7 Correct 70 ms 23944 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5720 KB Output is correct
10 Correct 115 ms 23108 KB Output is correct
11 Correct 68 ms 25648 KB Output is correct
12 Correct 61 ms 25516 KB Output is correct
13 Correct 64 ms 25544 KB Output is correct
14 Correct 99 ms 25536 KB Output is correct
15 Correct 111 ms 25464 KB Output is correct
16 Correct 90 ms 24644 KB Output is correct
17 Correct 90 ms 25108 KB Output is correct
18 Correct 2 ms 5720 KB Output is correct
19 Correct 113 ms 21972 KB Output is correct
20 Correct 102 ms 21700 KB Output is correct
21 Correct 103 ms 18852 KB Output is correct
22 Correct 99 ms 19172 KB Output is correct
23 Correct 93 ms 19656 KB Output is correct
24 Correct 89 ms 19924 KB Output is correct
25 Correct 90 ms 20168 KB Output is correct
26 Correct 87 ms 19908 KB Output is correct
27 Correct 98 ms 19544 KB Output is correct
28 Correct 117 ms 24264 KB Output is correct
29 Correct 101 ms 21540 KB Output is correct
30 Correct 96 ms 20548 KB Output is correct
31 Correct 91 ms 19748 KB Output is correct
32 Correct 94 ms 19556 KB Output is correct
33 Correct 82 ms 18120 KB Output is correct
34 Correct 109 ms 19124 KB Output is correct
35 Correct 101 ms 19892 KB Output is correct
36 Correct 79 ms 20244 KB Output is correct
37 Correct 100 ms 20188 KB Output is correct
38 Correct 113 ms 21408 KB Output is correct
39 Correct 82 ms 22372 KB Output is correct
40 Correct 81 ms 20404 KB Output is correct
41 Correct 97 ms 24872 KB Output is correct
42 Correct 105 ms 24772 KB Output is correct
43 Correct 96 ms 19080 KB Output is correct
44 Correct 129 ms 19264 KB Output is correct
45 Correct 94 ms 19292 KB Output is correct
46 Correct 112 ms 19184 KB Output is correct
47 Correct 119 ms 19020 KB Output is correct
48 Correct 112 ms 19272 KB Output is correct
49 Correct 103 ms 19016 KB Output is correct
50 Correct 112 ms 19140 KB Output is correct
51 Correct 99 ms 19424 KB Output is correct
52 Correct 119 ms 17564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5724 KB Output is correct
2 Correct 63 ms 23864 KB Output is correct
3 Correct 67 ms 24008 KB Output is correct
4 Correct 76 ms 24008 KB Output is correct
5 Correct 76 ms 23948 KB Output is correct
6 Correct 72 ms 23856 KB Output is correct
7 Correct 70 ms 23944 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5720 KB Output is correct
10 Correct 115 ms 23108 KB Output is correct
11 Correct 68 ms 25648 KB Output is correct
12 Correct 61 ms 25516 KB Output is correct
13 Correct 64 ms 25544 KB Output is correct
14 Correct 99 ms 25536 KB Output is correct
15 Correct 111 ms 25464 KB Output is correct
16 Correct 90 ms 24644 KB Output is correct
17 Correct 90 ms 25108 KB Output is correct
18 Correct 2 ms 5720 KB Output is correct
19 Correct 113 ms 21972 KB Output is correct
20 Correct 102 ms 21700 KB Output is correct
21 Correct 103 ms 18852 KB Output is correct
22 Correct 99 ms 19172 KB Output is correct
23 Correct 93 ms 19656 KB Output is correct
24 Correct 89 ms 19924 KB Output is correct
25 Correct 90 ms 20168 KB Output is correct
26 Correct 87 ms 19908 KB Output is correct
27 Correct 98 ms 19544 KB Output is correct
28 Correct 117 ms 24264 KB Output is correct
29 Correct 101 ms 21540 KB Output is correct
30 Correct 96 ms 20548 KB Output is correct
31 Correct 91 ms 19748 KB Output is correct
32 Correct 94 ms 19556 KB Output is correct
33 Correct 82 ms 18120 KB Output is correct
34 Correct 109 ms 19124 KB Output is correct
35 Correct 101 ms 19892 KB Output is correct
36 Correct 79 ms 20244 KB Output is correct
37 Correct 100 ms 20188 KB Output is correct
38 Correct 113 ms 21408 KB Output is correct
39 Correct 82 ms 22372 KB Output is correct
40 Correct 81 ms 20404 KB Output is correct
41 Correct 97 ms 24872 KB Output is correct
42 Correct 105 ms 24772 KB Output is correct
43 Correct 96 ms 19080 KB Output is correct
44 Correct 129 ms 19264 KB Output is correct
45 Correct 94 ms 19292 KB Output is correct
46 Correct 112 ms 19184 KB Output is correct
47 Correct 119 ms 19020 KB Output is correct
48 Correct 112 ms 19272 KB Output is correct
49 Correct 103 ms 19016 KB Output is correct
50 Correct 112 ms 19140 KB Output is correct
51 Correct 99 ms 19424 KB Output is correct
52 Correct 119 ms 17564 KB Output is correct
53 Correct 2 ms 5720 KB Output is correct
54 Incorrect 119 ms 19208 KB Output isn't correct
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Incorrect 2 ms 5976 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Incorrect 2 ms 5976 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5724 KB Output is correct
2 Correct 63 ms 23864 KB Output is correct
3 Correct 67 ms 24008 KB Output is correct
4 Correct 76 ms 24008 KB Output is correct
5 Correct 76 ms 23948 KB Output is correct
6 Correct 72 ms 23856 KB Output is correct
7 Correct 70 ms 23944 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5720 KB Output is correct
10 Correct 115 ms 23108 KB Output is correct
11 Correct 68 ms 25648 KB Output is correct
12 Correct 61 ms 25516 KB Output is correct
13 Correct 64 ms 25544 KB Output is correct
14 Correct 99 ms 25536 KB Output is correct
15 Correct 111 ms 25464 KB Output is correct
16 Correct 90 ms 24644 KB Output is correct
17 Correct 90 ms 25108 KB Output is correct
18 Correct 2 ms 5720 KB Output is correct
19 Correct 113 ms 21972 KB Output is correct
20 Correct 102 ms 21700 KB Output is correct
21 Correct 103 ms 18852 KB Output is correct
22 Correct 99 ms 19172 KB Output is correct
23 Correct 93 ms 19656 KB Output is correct
24 Correct 89 ms 19924 KB Output is correct
25 Correct 90 ms 20168 KB Output is correct
26 Correct 87 ms 19908 KB Output is correct
27 Correct 98 ms 19544 KB Output is correct
28 Correct 117 ms 24264 KB Output is correct
29 Correct 101 ms 21540 KB Output is correct
30 Correct 96 ms 20548 KB Output is correct
31 Correct 91 ms 19748 KB Output is correct
32 Correct 94 ms 19556 KB Output is correct
33 Correct 82 ms 18120 KB Output is correct
34 Correct 109 ms 19124 KB Output is correct
35 Correct 101 ms 19892 KB Output is correct
36 Correct 79 ms 20244 KB Output is correct
37 Correct 100 ms 20188 KB Output is correct
38 Correct 113 ms 21408 KB Output is correct
39 Correct 82 ms 22372 KB Output is correct
40 Correct 81 ms 20404 KB Output is correct
41 Correct 97 ms 24872 KB Output is correct
42 Correct 105 ms 24772 KB Output is correct
43 Correct 96 ms 19080 KB Output is correct
44 Correct 129 ms 19264 KB Output is correct
45 Correct 94 ms 19292 KB Output is correct
46 Correct 112 ms 19184 KB Output is correct
47 Correct 119 ms 19020 KB Output is correct
48 Correct 112 ms 19272 KB Output is correct
49 Correct 103 ms 19016 KB Output is correct
50 Correct 112 ms 19140 KB Output is correct
51 Correct 99 ms 19424 KB Output is correct
52 Correct 119 ms 17564 KB Output is correct
53 Correct 2 ms 5720 KB Output is correct
54 Incorrect 119 ms 19208 KB Output isn't correct
55 Halted 0 ms 0 KB -