# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
596785 | 2022-07-15T04:52:55 Z | 반딧불(#8447) | Reconstruction Project (JOI22_reconstruction) | C++17 | 5000 ms | 7508 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct unionFind{ int par[1002]; void init(int _n){ for(int i=1; i<=_n; i++) par[i] = i; } int find(int x){ if(x == par[x]) return x; return par[x] = find(par[x]); } void merge(int x, int y){ x = find(x), y = find(y); par[x] = y; } } dsu; struct Edge{ int x, y; ll w; Edge(){} Edge(int x, int y, ll w): x(x), y(y), w(w){} bool operator<(const Edge &r)const{ return w>r.w; } }; int n, m, q; Edge arr[100002]; int main(){ scanf("%d %d", &n, &m); for(int i=1; i<=m; i++) scanf("%d %d %lld", &arr[i].x, &arr[i].y, &arr[i].w); scanf("%d", &q); while(q--){ ll tmp; scanf("%lld", &tmp); priority_queue<Edge> pq; for(int i=1; i<=m; i++) pq.push(Edge(arr[i].x, arr[i].y, abs(arr[i].w - tmp))); dsu.init(n); ll ans = 0; while(!pq.empty()){ Edge tmp = pq.top(); pq.pop(); if(dsu.find(tmp.x) == dsu.find(tmp.y)) continue; dsu.merge(tmp.x, tmp.y); ans += tmp.w; } printf("%lld\n", ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 1 ms | 316 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 312 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 308 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 1 ms | 316 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 312 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 308 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 206 ms | 7160 KB | Output is correct |
21 | Correct | 179 ms | 7188 KB | Output is correct |
22 | Correct | 194 ms | 7180 KB | Output is correct |
23 | Correct | 181 ms | 7192 KB | Output is correct |
24 | Correct | 182 ms | 7180 KB | Output is correct |
25 | Correct | 177 ms | 7260 KB | Output is correct |
26 | Correct | 183 ms | 7212 KB | Output is correct |
27 | Correct | 192 ms | 7164 KB | Output is correct |
28 | Correct | 168 ms | 7292 KB | Output is correct |
29 | Correct | 135 ms | 7184 KB | Output is correct |
30 | Correct | 182 ms | 7272 KB | Output is correct |
31 | Correct | 173 ms | 7172 KB | Output is correct |
32 | Correct | 185 ms | 7176 KB | Output is correct |
33 | Correct | 180 ms | 7196 KB | Output is correct |
34 | Correct | 137 ms | 7248 KB | Output is correct |
35 | Correct | 192 ms | 7304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Execution timed out | 5070 ms | 7508 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 | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 1 ms | 316 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 312 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 308 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Execution timed out | 5083 ms | 1904 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 | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 1 ms | 316 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 312 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 308 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 206 ms | 7160 KB | Output is correct |
21 | Correct | 179 ms | 7188 KB | Output is correct |
22 | Correct | 194 ms | 7180 KB | Output is correct |
23 | Correct | 181 ms | 7192 KB | Output is correct |
24 | Correct | 182 ms | 7180 KB | Output is correct |
25 | Correct | 177 ms | 7260 KB | Output is correct |
26 | Correct | 183 ms | 7212 KB | Output is correct |
27 | Correct | 192 ms | 7164 KB | Output is correct |
28 | Correct | 168 ms | 7292 KB | Output is correct |
29 | Correct | 135 ms | 7184 KB | Output is correct |
30 | Correct | 182 ms | 7272 KB | Output is correct |
31 | Correct | 173 ms | 7172 KB | Output is correct |
32 | Correct | 185 ms | 7176 KB | Output is correct |
33 | Correct | 180 ms | 7196 KB | Output is correct |
34 | Correct | 137 ms | 7248 KB | Output is correct |
35 | Correct | 192 ms | 7304 KB | Output is correct |
36 | Execution timed out | 5081 ms | 7400 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 | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 1 ms | 316 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 312 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 308 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 206 ms | 7160 KB | Output is correct |
21 | Correct | 179 ms | 7188 KB | Output is correct |
22 | Correct | 194 ms | 7180 KB | Output is correct |
23 | Correct | 181 ms | 7192 KB | Output is correct |
24 | Correct | 182 ms | 7180 KB | Output is correct |
25 | Correct | 177 ms | 7260 KB | Output is correct |
26 | Correct | 183 ms | 7212 KB | Output is correct |
27 | Correct | 192 ms | 7164 KB | Output is correct |
28 | Correct | 168 ms | 7292 KB | Output is correct |
29 | Correct | 135 ms | 7184 KB | Output is correct |
30 | Correct | 182 ms | 7272 KB | Output is correct |
31 | Correct | 173 ms | 7172 KB | Output is correct |
32 | Correct | 185 ms | 7176 KB | Output is correct |
33 | Correct | 180 ms | 7196 KB | Output is correct |
34 | Correct | 137 ms | 7248 KB | Output is correct |
35 | Correct | 192 ms | 7304 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 0 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Execution timed out | 5070 ms | 7508 KB | Time limit exceeded |
40 | Halted | 0 ms | 0 KB | - |