Submission #821624

# Submission time Handle Problem Language Result Execution time Memory
821624 2023-08-11T12:11:28 Z rnl42 Reconstruction Project (JOI22_reconstruction) C++14
7 / 100
5000 ms 7680 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

#ifdef DEBUG
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgln() cerr << "\n"
#else
#define dbg(x) void(0)
#define dbgln() void(0)
#endif

struct Edge {
    int u, v, w;
    int val;
    bool operator<(const Edge& other) const {
        return val < other.val;
    }
};

struct UF {
    vector<int> uf;
    UF(int N) {
        uf.resize(N);
        iota(uf.begin(), uf.end(), 0);
    }
    int root(int u) {
        return u == uf[u] ? u : uf[u] = root(uf[u]);
    }
    void merge(int u, int v) {
        uf[root(u)] = root(v);
    }
};

int N, M, Q;
vector<Edge> edges;

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> N >> M;
    edges.resize(M);
    for (int i = 0; i < M; i++) {
        cin >> edges[i].u >> edges[i].v >> edges[i].w, edges[i].u--, edges[i].v--;
    }
    cin >> Q;
    int x;
    for (int i = 0; i < Q; i++) {
        cin >> x;
        for (int j = 0; j < M; j++) {
            edges[j].val = abs(edges[j].w-x);
        }
        sort(edges.begin(), edges.end());
        UF uf(N);
        int ans = 0;
        for (auto& e : edges) {
            if (uf.root(e.u) != uf.root(e.v)) {
                ans += e.val;
                uf.merge(e.u, e.v);
            }
        }
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 56 ms 5164 KB Output is correct
21 Correct 69 ms 5108 KB Output is correct
22 Correct 71 ms 5092 KB Output is correct
23 Correct 57 ms 5108 KB Output is correct
24 Correct 55 ms 5204 KB Output is correct
25 Correct 60 ms 5116 KB Output is correct
26 Correct 60 ms 5116 KB Output is correct
27 Correct 58 ms 5116 KB Output is correct
28 Correct 48 ms 5156 KB Output is correct
29 Correct 37 ms 5076 KB Output is correct
30 Correct 51 ms 5048 KB Output is correct
31 Correct 60 ms 5200 KB Output is correct
32 Correct 66 ms 5104 KB Output is correct
33 Correct 54 ms 5156 KB Output is correct
34 Correct 36 ms 5224 KB Output is correct
35 Correct 41 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 5055 ms 5380 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Execution timed out 5073 ms 7680 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 56 ms 5164 KB Output is correct
21 Correct 69 ms 5108 KB Output is correct
22 Correct 71 ms 5092 KB Output is correct
23 Correct 57 ms 5108 KB Output is correct
24 Correct 55 ms 5204 KB Output is correct
25 Correct 60 ms 5116 KB Output is correct
26 Correct 60 ms 5116 KB Output is correct
27 Correct 58 ms 5116 KB Output is correct
28 Correct 48 ms 5156 KB Output is correct
29 Correct 37 ms 5076 KB Output is correct
30 Correct 51 ms 5048 KB Output is correct
31 Correct 60 ms 5200 KB Output is correct
32 Correct 66 ms 5104 KB Output is correct
33 Correct 54 ms 5156 KB Output is correct
34 Correct 36 ms 5224 KB Output is correct
35 Correct 41 ms 5112 KB Output is correct
36 Execution timed out 5071 ms 5360 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 56 ms 5164 KB Output is correct
21 Correct 69 ms 5108 KB Output is correct
22 Correct 71 ms 5092 KB Output is correct
23 Correct 57 ms 5108 KB Output is correct
24 Correct 55 ms 5204 KB Output is correct
25 Correct 60 ms 5116 KB Output is correct
26 Correct 60 ms 5116 KB Output is correct
27 Correct 58 ms 5116 KB Output is correct
28 Correct 48 ms 5156 KB Output is correct
29 Correct 37 ms 5076 KB Output is correct
30 Correct 51 ms 5048 KB Output is correct
31 Correct 60 ms 5200 KB Output is correct
32 Correct 66 ms 5104 KB Output is correct
33 Correct 54 ms 5156 KB Output is correct
34 Correct 36 ms 5224 KB Output is correct
35 Correct 41 ms 5112 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 320 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Execution timed out 5055 ms 5380 KB Time limit exceeded
40 Halted 0 ms 0 KB -