Submission #884908

# Submission time Handle Problem Language Result Execution time Memory
884908 2023-12-08T16:29:58 Z amirhoseinfar1385 Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
428 ms 20400 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=505,maxm=100000+10;
struct yal{
    int u,v,w,ind;
    bool operator <(const yal a)const{
        if(a.w!=w){
            return w<a.w;
        }
        if(a.u!=u){
            return u<a.u;
        }
        return v<a.v;
    }
};
struct updy{
    int l,val,ted;
    updy(int a=0,int b=0,int c=0){
        l=a;
        val=b;
        ted=c;
    }
    bool operator <(const updy a)const{
        if(a.l!=l){
            return l<a.l;
        }
        if(a.val!=val){
            return val<a.val;
        }
        return ted<a.ted;
    }
}fupdy;
struct dsu{
    short par[maxn],sz[maxn];
    void clear(){
        memset(par,0,sizeof(par));
        memset(sz,0,sizeof(sz));
    }
    short root(short u){
        if(par[u]==0){
            return u;
        }
        return par[u]=root(par[u]);
    }
    bool con(short u,short v){
        u=root(u),v=root(v);
        if(u!=v){
            if(sz[u]<sz[v]){
                swap(u,v);
            }
            par[v]=u;
            sz[u]+=sz[v]+1;
            return 1;
        }
        return 0;
    }
}ds;
vector<updy>allq;
vector<yal>alle,v;
int n,m;

int upd(){
    ds.clear();
    for(int i=(int)v.size()-1;i>=0;i--){
        if(ds.con(v[i].u,v[i].v)==0){
            int ret=v[i].ind;
            v.erase(v.begin()+i);
            return ret;
        }
    }
    return -1;   
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    alle.resize(m);
    for(int i=0;i<m;i++){
        cin>>alle[i].u>>alle[i].v>>alle[i].w;
        allq.push_back(updy(alle[i].w,-2*alle[i].w,2));
    }
    sort(alle.begin(),alle.end());
    for(int i=0;i<m;i++){
        alle[i].ind=i;
    }
    for(int i=0;i<m;i++){
        v.push_back(alle[i]);
        int ind=upd();
        if(ind==-1){
            allq.push_back(updy(-1,alle[i].w,-1));    
        }
        else{
            int rl=(alle[i].w+alle[ind].w+1)/2;
            allq.push_back(updy(rl,alle[i].w,-1));
            allq.push_back(updy(rl,alle[ind].w,-1));
        }
    }
    sort(allq.rbegin(),allq.rend());
    int q;
    cin>>q;
    long long res=0,ted=0;
    for(int i=0;i<q;i++){
        int d;
        cin>>d;
        while((int)allq.size()>0&&allq.back().l<=d){
            auto x=allq.back();
            allq.pop_back();
            res+=x.val;
            ted+=x.ted;
        }
        long long mainres=res+d*ted;
        cout<<mainres<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 276 ms 9940 KB Output is correct
21 Correct 152 ms 9664 KB Output is correct
22 Correct 156 ms 9352 KB Output is correct
23 Correct 174 ms 9408 KB Output is correct
24 Correct 222 ms 9136 KB Output is correct
25 Correct 264 ms 9668 KB Output is correct
26 Correct 276 ms 9692 KB Output is correct
27 Correct 275 ms 9900 KB Output is correct
28 Correct 276 ms 8896 KB Output is correct
29 Correct 130 ms 8700 KB Output is correct
30 Correct 277 ms 9300 KB Output is correct
31 Correct 274 ms 9888 KB Output is correct
32 Correct 275 ms 9472 KB Output is correct
33 Correct 276 ms 8300 KB Output is correct
34 Correct 131 ms 9184 KB Output is correct
35 Correct 277 ms 8636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 314 ms 17816 KB Output is correct
5 Correct 315 ms 17744 KB Output is correct
6 Correct 319 ms 16568 KB Output is correct
7 Correct 226 ms 19956 KB Output is correct
8 Correct 201 ms 19864 KB Output is correct
9 Correct 199 ms 20400 KB Output is correct
10 Correct 311 ms 17192 KB Output is correct
11 Correct 203 ms 20084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 145 ms 12652 KB Output is correct
21 Correct 144 ms 12884 KB Output is correct
22 Correct 146 ms 12676 KB Output is correct
23 Correct 140 ms 12732 KB Output is correct
24 Correct 139 ms 12624 KB Output is correct
25 Correct 143 ms 12624 KB Output is correct
26 Correct 140 ms 12632 KB Output is correct
27 Correct 140 ms 12624 KB Output is correct
28 Correct 140 ms 12624 KB Output is correct
29 Correct 138 ms 12628 KB Output is correct
30 Correct 140 ms 12624 KB Output is correct
31 Correct 140 ms 12632 KB Output is correct
32 Correct 142 ms 13140 KB Output is correct
33 Correct 145 ms 12556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 276 ms 9940 KB Output is correct
21 Correct 152 ms 9664 KB Output is correct
22 Correct 156 ms 9352 KB Output is correct
23 Correct 174 ms 9408 KB Output is correct
24 Correct 222 ms 9136 KB Output is correct
25 Correct 264 ms 9668 KB Output is correct
26 Correct 276 ms 9692 KB Output is correct
27 Correct 275 ms 9900 KB Output is correct
28 Correct 276 ms 8896 KB Output is correct
29 Correct 130 ms 8700 KB Output is correct
30 Correct 277 ms 9300 KB Output is correct
31 Correct 274 ms 9888 KB Output is correct
32 Correct 275 ms 9472 KB Output is correct
33 Correct 276 ms 8300 KB Output is correct
34 Correct 131 ms 9184 KB Output is correct
35 Correct 277 ms 8636 KB Output is correct
36 Correct 284 ms 9924 KB Output is correct
37 Correct 157 ms 9040 KB Output is correct
38 Correct 158 ms 8636 KB Output is correct
39 Correct 186 ms 10068 KB Output is correct
40 Correct 225 ms 9512 KB Output is correct
41 Correct 270 ms 10168 KB Output is correct
42 Correct 277 ms 10060 KB Output is correct
43 Correct 280 ms 9884 KB Output is correct
44 Correct 281 ms 8640 KB Output is correct
45 Correct 131 ms 9668 KB Output is correct
46 Correct 278 ms 9396 KB Output is correct
47 Correct 282 ms 8876 KB Output is correct
48 Correct 289 ms 8892 KB Output is correct
49 Correct 279 ms 10216 KB Output is correct
50 Correct 134 ms 9060 KB Output is correct
51 Correct 278 ms 10024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 276 ms 9940 KB Output is correct
21 Correct 152 ms 9664 KB Output is correct
22 Correct 156 ms 9352 KB Output is correct
23 Correct 174 ms 9408 KB Output is correct
24 Correct 222 ms 9136 KB Output is correct
25 Correct 264 ms 9668 KB Output is correct
26 Correct 276 ms 9692 KB Output is correct
27 Correct 275 ms 9900 KB Output is correct
28 Correct 276 ms 8896 KB Output is correct
29 Correct 130 ms 8700 KB Output is correct
30 Correct 277 ms 9300 KB Output is correct
31 Correct 274 ms 9888 KB Output is correct
32 Correct 275 ms 9472 KB Output is correct
33 Correct 276 ms 8300 KB Output is correct
34 Correct 131 ms 9184 KB Output is correct
35 Correct 277 ms 8636 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 596 KB Output is correct
39 Correct 314 ms 17816 KB Output is correct
40 Correct 315 ms 17744 KB Output is correct
41 Correct 319 ms 16568 KB Output is correct
42 Correct 226 ms 19956 KB Output is correct
43 Correct 201 ms 19864 KB Output is correct
44 Correct 199 ms 20400 KB Output is correct
45 Correct 311 ms 17192 KB Output is correct
46 Correct 203 ms 20084 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 145 ms 12652 KB Output is correct
49 Correct 144 ms 12884 KB Output is correct
50 Correct 146 ms 12676 KB Output is correct
51 Correct 140 ms 12732 KB Output is correct
52 Correct 139 ms 12624 KB Output is correct
53 Correct 143 ms 12624 KB Output is correct
54 Correct 140 ms 12632 KB Output is correct
55 Correct 140 ms 12624 KB Output is correct
56 Correct 140 ms 12624 KB Output is correct
57 Correct 138 ms 12628 KB Output is correct
58 Correct 140 ms 12624 KB Output is correct
59 Correct 140 ms 12632 KB Output is correct
60 Correct 142 ms 13140 KB Output is correct
61 Correct 145 ms 12556 KB Output is correct
62 Correct 284 ms 9924 KB Output is correct
63 Correct 157 ms 9040 KB Output is correct
64 Correct 158 ms 8636 KB Output is correct
65 Correct 186 ms 10068 KB Output is correct
66 Correct 225 ms 9512 KB Output is correct
67 Correct 270 ms 10168 KB Output is correct
68 Correct 277 ms 10060 KB Output is correct
69 Correct 280 ms 9884 KB Output is correct
70 Correct 281 ms 8640 KB Output is correct
71 Correct 131 ms 9668 KB Output is correct
72 Correct 278 ms 9396 KB Output is correct
73 Correct 282 ms 8876 KB Output is correct
74 Correct 289 ms 8892 KB Output is correct
75 Correct 279 ms 10216 KB Output is correct
76 Correct 134 ms 9060 KB Output is correct
77 Correct 278 ms 10024 KB Output is correct
78 Correct 419 ms 15724 KB Output is correct
79 Correct 326 ms 18892 KB Output is correct
80 Correct 296 ms 16756 KB Output is correct
81 Correct 313 ms 18108 KB Output is correct
82 Correct 360 ms 15804 KB Output is correct
83 Correct 405 ms 16416 KB Output is correct
84 Correct 416 ms 16404 KB Output is correct
85 Correct 412 ms 17460 KB Output is correct
86 Correct 414 ms 16736 KB Output is correct
87 Correct 265 ms 18204 KB Output is correct
88 Correct 418 ms 15660 KB Output is correct
89 Correct 415 ms 17348 KB Output is correct
90 Correct 424 ms 15900 KB Output is correct
91 Correct 410 ms 16828 KB Output is correct
92 Correct 268 ms 20348 KB Output is correct
93 Correct 428 ms 18460 KB Output is correct