# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
556250 | 2022-05-02T16:08:46 Z | 600Mihnea | Reconstruction Project (JOI22_reconstruction) | C++17 | 5000 ms | 4748 KB |
#include <bits/stdc++.h> bool home = 1; using namespace std; typedef long long ll; int wglob; struct Edge{ int a; int b; int w; }; bool operator < (Edge a,Edge b) { return abs(wglob-a.w)<abs(wglob-b.w); } const int N=500+7; const int M=100000+7; const int Q=1000000+7; int n; int m; int q; int t[N]; Edge edges[M]; int root(int a) { if (t[a]==a) return a; return t[a]=root(t[a]); } void join(int a,int b) { t[root(a)]=root(b); } signed main() { #ifdef ONLINE_JUDGE home = 0; #endif home=0; if (home) { freopen("I_am_iron_man", "r", stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } cin>>n>>m; for (int i=1;i<=m;i++) { cin>>edges[i].a>>edges[i].b>>edges[i].w; } cin>>q; for (int iq=1;iq<=q;iq++) { int w; cin>>w; wglob=w; sort(edges+1,edges+m+1); for (int i=1;i<=n;i++) t[i]=i; ll sol=0; for (int i=1;i<=m;i++) { int a=edges[i].a; int b=edges[i].b; int cost=abs(wglob-edges[i].w); if (root(a)!=root(b)) { join(a,b); sol+=cost; } } cout<<sol<<"\n"; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 328 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 212 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 | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 212 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 328 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 212 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 | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 212 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 | 328 KB | Output is correct |
20 | Correct | 75 ms | 3092 KB | Output is correct |
21 | Correct | 75 ms | 1468 KB | Output is correct |
22 | Correct | 77 ms | 1396 KB | Output is correct |
23 | Correct | 76 ms | 1488 KB | Output is correct |
24 | Correct | 88 ms | 1480 KB | Output is correct |
25 | Correct | 78 ms | 1488 KB | Output is correct |
26 | Correct | 83 ms | 3184 KB | Output is correct |
27 | Correct | 77 ms | 2976 KB | Output is correct |
28 | Correct | 52 ms | 2996 KB | Output is correct |
29 | Correct | 52 ms | 3072 KB | Output is correct |
30 | Correct | 74 ms | 3164 KB | Output is correct |
31 | Correct | 81 ms | 3036 KB | Output is correct |
32 | Correct | 75 ms | 3060 KB | Output is correct |
33 | Correct | 71 ms | 1388 KB | Output is correct |
34 | Correct | 53 ms | 3196 KB | Output is correct |
35 | Correct | 59 ms | 3172 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Execution timed out | 5051 ms | 3368 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 328 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 212 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 | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 212 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 | 5044 ms | 4748 KB | Time limit exceeded |
21 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 328 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 212 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 | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 212 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 | 328 KB | Output is correct |
20 | Correct | 75 ms | 3092 KB | Output is correct |
21 | Correct | 75 ms | 1468 KB | Output is correct |
22 | Correct | 77 ms | 1396 KB | Output is correct |
23 | Correct | 76 ms | 1488 KB | Output is correct |
24 | Correct | 88 ms | 1480 KB | Output is correct |
25 | Correct | 78 ms | 1488 KB | Output is correct |
26 | Correct | 83 ms | 3184 KB | Output is correct |
27 | Correct | 77 ms | 2976 KB | Output is correct |
28 | Correct | 52 ms | 2996 KB | Output is correct |
29 | Correct | 52 ms | 3072 KB | Output is correct |
30 | Correct | 74 ms | 3164 KB | Output is correct |
31 | Correct | 81 ms | 3036 KB | Output is correct |
32 | Correct | 75 ms | 3060 KB | Output is correct |
33 | Correct | 71 ms | 1388 KB | Output is correct |
34 | Correct | 53 ms | 3196 KB | Output is correct |
35 | Correct | 59 ms | 3172 KB | Output is correct |
36 | Execution timed out | 5003 ms | 3396 KB | Time limit exceeded |
37 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 328 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 212 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 | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 212 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 | 328 KB | Output is correct |
20 | Correct | 75 ms | 3092 KB | Output is correct |
21 | Correct | 75 ms | 1468 KB | Output is correct |
22 | Correct | 77 ms | 1396 KB | Output is correct |
23 | Correct | 76 ms | 1488 KB | Output is correct |
24 | Correct | 88 ms | 1480 KB | Output is correct |
25 | Correct | 78 ms | 1488 KB | Output is correct |
26 | Correct | 83 ms | 3184 KB | Output is correct |
27 | Correct | 77 ms | 2976 KB | Output is correct |
28 | Correct | 52 ms | 2996 KB | Output is correct |
29 | Correct | 52 ms | 3072 KB | Output is correct |
30 | Correct | 74 ms | 3164 KB | Output is correct |
31 | Correct | 81 ms | 3036 KB | Output is correct |
32 | Correct | 75 ms | 3060 KB | Output is correct |
33 | Correct | 71 ms | 1388 KB | Output is correct |
34 | Correct | 53 ms | 3196 KB | Output is correct |
35 | Correct | 59 ms | 3172 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Execution timed out | 5051 ms | 3368 KB | Time limit exceeded |
40 | Halted | 0 ms | 0 KB | - |