# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
556668 | 2022-05-03T13:57:26 Z | 600Mihnea | Reconstruction Project (JOI22_reconstruction) | C++17 | 5000 ms | 22496 KB |
#include <bits/stdc++.h> bool home = 1; using namespace std; typedef long long ll; struct Edge{ int a; int b; int w; }; bool operator < (Edge a,Edge b) { return a.w<b.w; } const int N=500+7; const int M=100000+7; const int Q=1000000+7; const int INF=(int)1e9+7; int n; int m; int q; int t[N]; Edge edges[M]; void clr() { for(int i=1;i<=n;i++) t[i]=i; } 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); } int smallest[M]; int biggest[M]; 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; smallest[i]=-INF; biggest[i]=+INF; } sort(edges+1,edges+m+1); for (int i=2;i<=m;i++){ assert(edges[i-1].w<=edges[i].w); } for (int i=1;i<=m;i++) { clr(); int low=i-1; while (low>=1&&root(edges[i].a)!=root(edges[i].b)) { join(edges[low].a,edges[low].b); low--; } if(root(edges[i].a)==root(edges[i].b)) low++; clr(); int high=i+1; while(high<=m&&root(edges[i].a)!=root(edges[i].b)) { join(edges[high].a,edges[high].b); high++; } if(root(edges[i].a)==root(edges[i].b)) high--; if (low>=1) smallest[i]=(edges[low].w+edges[i].w+1)/2; if (high<=m) biggest[i]=(edges[high].w+edges[i].w-1)/2; } cin>>q; for (int iq=1;iq<=q;iq++) { int w; cin>>w; ll sol=0; for(int i=1;i<=m;i++) { if (smallest[i]<=w&&w<=biggest[i]) { sol+=abs(edges[i].w-w); } } cout<<sol<<"\n"; } } /** 1 : -1 4 2 : -1 5 3 : 4 7 4 : -1 11 5 : 5 9 6 : -1 10 7 : 7 1000000001 8 : 9 1000000001 9 : 10 1000000001 10 : 11 1000000001 **/
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 ms | 212 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 | 0 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 ms | 212 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 | 0 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 2133 ms | 2256 KB | Output is correct |
21 | Correct | 1210 ms | 2272 KB | Output is correct |
22 | Correct | 1302 ms | 2304 KB | Output is correct |
23 | Correct | 1472 ms | 2268 KB | Output is correct |
24 | Correct | 1789 ms | 2256 KB | Output is correct |
25 | Correct | 2168 ms | 2272 KB | Output is correct |
26 | Correct | 2086 ms | 4052 KB | Output is correct |
27 | Correct | 2096 ms | 3788 KB | Output is correct |
28 | Correct | 2091 ms | 3856 KB | Output is correct |
29 | Correct | 2094 ms | 3856 KB | Output is correct |
30 | Correct | 2098 ms | 3960 KB | Output is correct |
31 | Correct | 2103 ms | 3896 KB | Output is correct |
32 | Correct | 2084 ms | 3880 KB | Output is correct |
33 | Correct | 2090 ms | 2264 KB | Output is correct |
34 | Correct | 2087 ms | 3988 KB | Output is correct |
35 | Correct | 2115 ms | 3948 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 284 KB | Output is correct |
4 | Execution timed out | 5067 ms | 3268 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 ms | 212 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 | 0 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1897 ms | 21940 KB | Output is correct |
21 | Correct | 2307 ms | 17304 KB | Output is correct |
22 | Correct | 2009 ms | 21568 KB | Output is correct |
23 | Correct | 2043 ms | 22052 KB | Output is correct |
24 | Correct | 1907 ms | 22184 KB | Output is correct |
25 | Correct | 1892 ms | 21880 KB | Output is correct |
26 | Correct | 1810 ms | 22100 KB | Output is correct |
27 | Correct | 1946 ms | 22472 KB | Output is correct |
28 | Correct | 1794 ms | 22140 KB | Output is correct |
29 | Correct | 1778 ms | 22360 KB | Output is correct |
30 | Correct | 1952 ms | 21972 KB | Output is correct |
31 | Correct | 1745 ms | 21876 KB | Output is correct |
32 | Correct | 1663 ms | 22496 KB | Output is correct |
33 | Correct | 1825 ms | 22032 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 ms | 212 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 | 0 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 2133 ms | 2256 KB | Output is correct |
21 | Correct | 1210 ms | 2272 KB | Output is correct |
22 | Correct | 1302 ms | 2304 KB | Output is correct |
23 | Correct | 1472 ms | 2268 KB | Output is correct |
24 | Correct | 1789 ms | 2256 KB | Output is correct |
25 | Correct | 2168 ms | 2272 KB | Output is correct |
26 | Correct | 2086 ms | 4052 KB | Output is correct |
27 | Correct | 2096 ms | 3788 KB | Output is correct |
28 | Correct | 2091 ms | 3856 KB | Output is correct |
29 | Correct | 2094 ms | 3856 KB | Output is correct |
30 | Correct | 2098 ms | 3960 KB | Output is correct |
31 | Correct | 2103 ms | 3896 KB | Output is correct |
32 | Correct | 2084 ms | 3880 KB | Output is correct |
33 | Correct | 2090 ms | 2264 KB | Output is correct |
34 | Correct | 2087 ms | 3988 KB | Output is correct |
35 | Correct | 2115 ms | 3948 KB | Output is correct |
36 | Correct | 3440 ms | 4292 KB | Output is correct |
37 | Correct | 2604 ms | 4268 KB | Output is correct |
38 | Correct | 2720 ms | 2456 KB | Output is correct |
39 | Correct | 2848 ms | 2480 KB | Output is correct |
40 | Correct | 3215 ms | 2460 KB | Output is correct |
41 | Correct | 3569 ms | 2392 KB | Output is correct |
42 | Correct | 3554 ms | 3436 KB | Output is correct |
43 | Correct | 3601 ms | 3736 KB | Output is correct |
44 | Correct | 3507 ms | 4284 KB | Output is correct |
45 | Correct | 3516 ms | 4172 KB | Output is correct |
46 | Correct | 3475 ms | 4236 KB | Output is correct |
47 | Correct | 3523 ms | 4216 KB | Output is correct |
48 | Correct | 3505 ms | 3980 KB | Output is correct |
49 | Correct | 3507 ms | 2428 KB | Output is correct |
50 | Correct | 3455 ms | 2520 KB | Output is correct |
51 | Correct | 3505 ms | 2608 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 ms | 212 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 | 0 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 2133 ms | 2256 KB | Output is correct |
21 | Correct | 1210 ms | 2272 KB | Output is correct |
22 | Correct | 1302 ms | 2304 KB | Output is correct |
23 | Correct | 1472 ms | 2268 KB | Output is correct |
24 | Correct | 1789 ms | 2256 KB | Output is correct |
25 | Correct | 2168 ms | 2272 KB | Output is correct |
26 | Correct | 2086 ms | 4052 KB | Output is correct |
27 | Correct | 2096 ms | 3788 KB | Output is correct |
28 | Correct | 2091 ms | 3856 KB | Output is correct |
29 | Correct | 2094 ms | 3856 KB | Output is correct |
30 | Correct | 2098 ms | 3960 KB | Output is correct |
31 | Correct | 2103 ms | 3896 KB | Output is correct |
32 | Correct | 2084 ms | 3880 KB | Output is correct |
33 | Correct | 2090 ms | 2264 KB | Output is correct |
34 | Correct | 2087 ms | 3988 KB | Output is correct |
35 | Correct | 2115 ms | 3948 KB | Output is correct |
36 | Correct | 0 ms | 340 KB | Output is correct |
37 | Correct | 0 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 284 KB | Output is correct |
39 | Execution timed out | 5067 ms | 3268 KB | Time limit exceeded |
40 | Halted | 0 ms | 0 KB | - |