답안 #781690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781690 2023-07-13T10:03:49 Z PoonYaPat Reconstruction Project (JOI22_reconstruction) C++14
100 / 100
1273 ms 35060 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct Edge {
    ll w,a,b;
    bool operator < (const Edge &o) const {return w<o.w;}
};

int n,m,bef[100005],aft[100005],p[505],r[505];
Edge edge[100005];
vector<Edge> v;

int find(int x) {
    while (x!=p[x]) x=p[x];
    return x;
}

void unite(int a, int b) {
    a=find(a); b=find(b);
    if (a!=b) {
        if (r[a]>r[b]) swap(a,b);
        p[a]=b;
        if (r[a]==r[b]) ++r[b];
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; ++i) cin>>edge[i].a>>edge[i].b>>edge[i].w;
    sort(edge+1,edge+m+1);

    for (int i=1; i<=m; ++i) {
        bef[i]=i-1;
        for (int j=1; j<=n; ++j) r[j]=1, p[j]=j;
        while (bef[i]) {
            unite(edge[bef[i]].a,edge[bef[i]].b);
            if (find(edge[i].a)==find(edge[i].b)) break;
            --bef[i];
        }
    }

    for (int i=1; i<=m; ++i) aft[i]=m+1;
    for (int i=1; i<=m; ++i) aft[bef[i]]=i;

    for (int i=1; i<=m; ++i) {
        if (bef[i]) v.push_back({(edge[i].w+edge[bef[i]].w)/2+1,-1ll,edge[i].w});
        else v.push_back({0,-1ll,edge[i].w});

        v.push_back({edge[i].w,2ll,-2*edge[i].w});

        if (aft[i]!=m+1) v.push_back({(edge[i].w+edge[aft[i]].w)/2+1,-1ll,edge[i].w});
    }
    sort(v.begin(),v.end());

    int q; cin>>q;
    int idx=0;
    ll cnt1=0,cnt2=0;
    while (q--) {
        ll x; cin>>x;
        while (idx<v.size() && v[idx].w<=x) {
            cnt1+=v[idx].a;
            cnt2+=v[idx].b;
            ++idx;
        }
        cout<<cnt1*x+cnt2<<"\n";
    }
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         while (idx<v.size() && v[idx].w<=x) {
      |                ~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1107 ms 17520 KB Output is correct
21 Correct 673 ms 17608 KB Output is correct
22 Correct 743 ms 17548 KB Output is correct
23 Correct 844 ms 17572 KB Output is correct
24 Correct 1037 ms 17540 KB Output is correct
25 Correct 1148 ms 17588 KB Output is correct
26 Correct 1103 ms 17624 KB Output is correct
27 Correct 1102 ms 17552 KB Output is correct
28 Correct 1082 ms 17612 KB Output is correct
29 Correct 1099 ms 17576 KB Output is correct
30 Correct 1105 ms 17648 KB Output is correct
31 Correct 1095 ms 17516 KB Output is correct
32 Correct 1113 ms 17496 KB Output is correct
33 Correct 1112 ms 17528 KB Output is correct
34 Correct 1069 ms 17692 KB Output is correct
35 Correct 1099 ms 17516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 949 ms 32992 KB Output is correct
5 Correct 957 ms 32984 KB Output is correct
6 Correct 943 ms 33036 KB Output is correct
7 Correct 518 ms 34856 KB Output is correct
8 Correct 383 ms 34928 KB Output is correct
9 Correct 333 ms 35060 KB Output is correct
10 Correct 942 ms 33080 KB Output is correct
11 Correct 400 ms 35044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 161 ms 22448 KB Output is correct
21 Correct 160 ms 22488 KB Output is correct
22 Correct 164 ms 22424 KB Output is correct
23 Correct 157 ms 22452 KB Output is correct
24 Correct 157 ms 22428 KB Output is correct
25 Correct 168 ms 22340 KB Output is correct
26 Correct 162 ms 22412 KB Output is correct
27 Correct 162 ms 22376 KB Output is correct
28 Correct 159 ms 22412 KB Output is correct
29 Correct 193 ms 22344 KB Output is correct
30 Correct 155 ms 22484 KB Output is correct
31 Correct 172 ms 22292 KB Output is correct
32 Correct 163 ms 23140 KB Output is correct
33 Correct 179 ms 22316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1107 ms 17520 KB Output is correct
21 Correct 673 ms 17608 KB Output is correct
22 Correct 743 ms 17548 KB Output is correct
23 Correct 844 ms 17572 KB Output is correct
24 Correct 1037 ms 17540 KB Output is correct
25 Correct 1148 ms 17588 KB Output is correct
26 Correct 1103 ms 17624 KB Output is correct
27 Correct 1102 ms 17552 KB Output is correct
28 Correct 1082 ms 17612 KB Output is correct
29 Correct 1099 ms 17576 KB Output is correct
30 Correct 1105 ms 17648 KB Output is correct
31 Correct 1095 ms 17516 KB Output is correct
32 Correct 1113 ms 17496 KB Output is correct
33 Correct 1112 ms 17528 KB Output is correct
34 Correct 1069 ms 17692 KB Output is correct
35 Correct 1099 ms 17516 KB Output is correct
36 Correct 1088 ms 17768 KB Output is correct
37 Correct 653 ms 17720 KB Output is correct
38 Correct 720 ms 17760 KB Output is correct
39 Correct 855 ms 17796 KB Output is correct
40 Correct 1049 ms 17780 KB Output is correct
41 Correct 1139 ms 17736 KB Output is correct
42 Correct 1128 ms 17724 KB Output is correct
43 Correct 1081 ms 17744 KB Output is correct
44 Correct 1094 ms 17788 KB Output is correct
45 Correct 1104 ms 17808 KB Output is correct
46 Correct 1097 ms 17680 KB Output is correct
47 Correct 1077 ms 17788 KB Output is correct
48 Correct 1103 ms 17804 KB Output is correct
49 Correct 1083 ms 17844 KB Output is correct
50 Correct 1089 ms 17924 KB Output is correct
51 Correct 1102 ms 17876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1107 ms 17520 KB Output is correct
21 Correct 673 ms 17608 KB Output is correct
22 Correct 743 ms 17548 KB Output is correct
23 Correct 844 ms 17572 KB Output is correct
24 Correct 1037 ms 17540 KB Output is correct
25 Correct 1148 ms 17588 KB Output is correct
26 Correct 1103 ms 17624 KB Output is correct
27 Correct 1102 ms 17552 KB Output is correct
28 Correct 1082 ms 17612 KB Output is correct
29 Correct 1099 ms 17576 KB Output is correct
30 Correct 1105 ms 17648 KB Output is correct
31 Correct 1095 ms 17516 KB Output is correct
32 Correct 1113 ms 17496 KB Output is correct
33 Correct 1112 ms 17528 KB Output is correct
34 Correct 1069 ms 17692 KB Output is correct
35 Correct 1099 ms 17516 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 949 ms 32992 KB Output is correct
40 Correct 957 ms 32984 KB Output is correct
41 Correct 943 ms 33036 KB Output is correct
42 Correct 518 ms 34856 KB Output is correct
43 Correct 383 ms 34928 KB Output is correct
44 Correct 333 ms 35060 KB Output is correct
45 Correct 942 ms 33080 KB Output is correct
46 Correct 400 ms 35044 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 161 ms 22448 KB Output is correct
49 Correct 160 ms 22488 KB Output is correct
50 Correct 164 ms 22424 KB Output is correct
51 Correct 157 ms 22452 KB Output is correct
52 Correct 157 ms 22428 KB Output is correct
53 Correct 168 ms 22340 KB Output is correct
54 Correct 162 ms 22412 KB Output is correct
55 Correct 162 ms 22376 KB Output is correct
56 Correct 159 ms 22412 KB Output is correct
57 Correct 193 ms 22344 KB Output is correct
58 Correct 155 ms 22484 KB Output is correct
59 Correct 172 ms 22292 KB Output is correct
60 Correct 163 ms 23140 KB Output is correct
61 Correct 179 ms 22316 KB Output is correct
62 Correct 1088 ms 17768 KB Output is correct
63 Correct 653 ms 17720 KB Output is correct
64 Correct 720 ms 17760 KB Output is correct
65 Correct 855 ms 17796 KB Output is correct
66 Correct 1049 ms 17780 KB Output is correct
67 Correct 1139 ms 17736 KB Output is correct
68 Correct 1128 ms 17724 KB Output is correct
69 Correct 1081 ms 17744 KB Output is correct
70 Correct 1094 ms 17788 KB Output is correct
71 Correct 1104 ms 17808 KB Output is correct
72 Correct 1097 ms 17680 KB Output is correct
73 Correct 1077 ms 17788 KB Output is correct
74 Correct 1103 ms 17804 KB Output is correct
75 Correct 1083 ms 17844 KB Output is correct
76 Correct 1089 ms 17924 KB Output is correct
77 Correct 1102 ms 17876 KB Output is correct
78 Correct 1255 ms 32060 KB Output is correct
79 Correct 802 ms 33980 KB Output is correct
80 Correct 865 ms 32984 KB Output is correct
81 Correct 968 ms 33120 KB Output is correct
82 Correct 1187 ms 32092 KB Output is correct
83 Correct 1273 ms 32036 KB Output is correct
84 Correct 1253 ms 32064 KB Output is correct
85 Correct 1221 ms 32024 KB Output is correct
86 Correct 1217 ms 31916 KB Output is correct
87 Correct 1241 ms 33628 KB Output is correct
88 Correct 1246 ms 32024 KB Output is correct
89 Correct 1223 ms 32100 KB Output is correct
90 Correct 1223 ms 32180 KB Output is correct
91 Correct 1244 ms 31904 KB Output is correct
92 Correct 1234 ms 34864 KB Output is correct
93 Correct 1224 ms 33116 KB Output is correct