Submission #960289

# Submission time Handle Problem Language Result Execution time Memory
960289 2024-04-10T07:34:38 Z thinknoexit Security Guard (JOI23_guard) C++17
0 / 100
9 ms 7228 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100100;
int a[N];
vector<int> adj[N];
struct A {
    int u, v;
    bool operator < (const A& o) const {
        return min(a[u], a[v]) < min(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]);
}
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;
    if (m != n - 1) return 0;
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
        p[i] = i;
    }
    while (m--) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int idx = max_element(a + 1, a + 1 + n) - a;
    dfs(idx);
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Runtime error 9 ms 7228 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Runtime error 9 ms 7228 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Runtime error 9 ms 7228 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Runtime error 9 ms 7228 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2904 KB Output is correct
2 Incorrect 1 ms 2908 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2904 KB Output is correct
2 Incorrect 1 ms 2908 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Runtime error 9 ms 7228 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -