Submission #884901

# Submission time Handle Problem Language Result Execution time Memory
884901 2023-12-08T16:21:38 Z amirhoseinfar1385 Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
416 ms 20404 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{
    int par[maxn],sz[maxn];
    void clear(){
        memset(par,0,sizeof(par));
        memset(sz,0,sizeof(sz));
    }
    int root(int u){
        if(par[u]==0){
            return u;
        }
        return par[u]=root(par[u]);
    }
    int con(int u,int 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--){
       // cout<<"ha: "<<v[i].u<<" "<<v[i].v<<" "<<v[i].ind<<"\n";
        if(ds.con(v[i].u,v[i].v)==0){
         //   cout<<"nababa"<<endl;
            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;
           // cout<<i<<" "<<ind<<" "<<alle[i].w<<" "<<alle[ind].w<<" wtf"<<endl;
            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;
            //cout<<"outy: "<<x.val<<" "<<x.ted<<" "<<x.l<<" "<<d<<"\n";
        }
        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 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 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 344 KB Output is correct
17 Correct 1 ms 344 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 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 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 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 274 ms 8752 KB Output is correct
21 Correct 149 ms 8256 KB Output is correct
22 Correct 151 ms 9840 KB Output is correct
23 Correct 170 ms 9508 KB Output is correct
24 Correct 214 ms 8968 KB Output is correct
25 Correct 256 ms 9576 KB Output is correct
26 Correct 272 ms 8712 KB Output is correct
27 Correct 270 ms 9464 KB Output is correct
28 Correct 268 ms 9172 KB Output is correct
29 Correct 124 ms 10096 KB Output is correct
30 Correct 270 ms 9408 KB Output is correct
31 Correct 269 ms 8700 KB Output is correct
32 Correct 274 ms 9920 KB Output is correct
33 Correct 270 ms 9152 KB Output is correct
34 Correct 131 ms 8852 KB Output is correct
35 Correct 275 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 315 ms 18200 KB Output is correct
5 Correct 313 ms 16820 KB Output is correct
6 Correct 313 ms 17084 KB Output is correct
7 Correct 229 ms 19948 KB Output is correct
8 Correct 207 ms 20404 KB Output is correct
9 Correct 206 ms 19640 KB Output is correct
10 Correct 313 ms 17080 KB Output is correct
11 Correct 205 ms 20144 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 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 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 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 144 ms 12804 KB Output is correct
21 Correct 145 ms 12884 KB Output is correct
22 Correct 143 ms 12628 KB Output is correct
23 Correct 148 ms 12704 KB Output is correct
24 Correct 143 ms 12624 KB Output is correct
25 Correct 151 ms 13044 KB Output is correct
26 Correct 142 ms 12624 KB Output is correct
27 Correct 145 ms 12768 KB Output is correct
28 Correct 143 ms 12640 KB Output is correct
29 Correct 145 ms 12584 KB Output is correct
30 Correct 143 ms 12600 KB Output is correct
31 Correct 142 ms 12624 KB Output is correct
32 Correct 150 ms 13392 KB Output is correct
33 Correct 143 ms 12460 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 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 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 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 274 ms 8752 KB Output is correct
21 Correct 149 ms 8256 KB Output is correct
22 Correct 151 ms 9840 KB Output is correct
23 Correct 170 ms 9508 KB Output is correct
24 Correct 214 ms 8968 KB Output is correct
25 Correct 256 ms 9576 KB Output is correct
26 Correct 272 ms 8712 KB Output is correct
27 Correct 270 ms 9464 KB Output is correct
28 Correct 268 ms 9172 KB Output is correct
29 Correct 124 ms 10096 KB Output is correct
30 Correct 270 ms 9408 KB Output is correct
31 Correct 269 ms 8700 KB Output is correct
32 Correct 274 ms 9920 KB Output is correct
33 Correct 270 ms 9152 KB Output is correct
34 Correct 131 ms 8852 KB Output is correct
35 Correct 275 ms 8192 KB Output is correct
36 Correct 274 ms 9668 KB Output is correct
37 Correct 157 ms 8904 KB Output is correct
38 Correct 164 ms 8892 KB Output is correct
39 Correct 174 ms 10052 KB Output is correct
40 Correct 214 ms 8128 KB Output is correct
41 Correct 261 ms 9892 KB Output is correct
42 Correct 277 ms 8660 KB Output is correct
43 Correct 272 ms 9360 KB Output is correct
44 Correct 269 ms 8716 KB Output is correct
45 Correct 121 ms 9660 KB Output is correct
46 Correct 271 ms 8124 KB Output is correct
47 Correct 280 ms 9332 KB Output is correct
48 Correct 273 ms 8328 KB Output is correct
49 Correct 272 ms 8616 KB Output is correct
50 Correct 133 ms 9924 KB Output is correct
51 Correct 271 ms 9412 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 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 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 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 274 ms 8752 KB Output is correct
21 Correct 149 ms 8256 KB Output is correct
22 Correct 151 ms 9840 KB Output is correct
23 Correct 170 ms 9508 KB Output is correct
24 Correct 214 ms 8968 KB Output is correct
25 Correct 256 ms 9576 KB Output is correct
26 Correct 272 ms 8712 KB Output is correct
27 Correct 270 ms 9464 KB Output is correct
28 Correct 268 ms 9172 KB Output is correct
29 Correct 124 ms 10096 KB Output is correct
30 Correct 270 ms 9408 KB Output is correct
31 Correct 269 ms 8700 KB Output is correct
32 Correct 274 ms 9920 KB Output is correct
33 Correct 270 ms 9152 KB Output is correct
34 Correct 131 ms 8852 KB Output is correct
35 Correct 275 ms 8192 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 315 ms 18200 KB Output is correct
40 Correct 313 ms 16820 KB Output is correct
41 Correct 313 ms 17084 KB Output is correct
42 Correct 229 ms 19948 KB Output is correct
43 Correct 207 ms 20404 KB Output is correct
44 Correct 206 ms 19640 KB Output is correct
45 Correct 313 ms 17080 KB Output is correct
46 Correct 205 ms 20144 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 144 ms 12804 KB Output is correct
49 Correct 145 ms 12884 KB Output is correct
50 Correct 143 ms 12628 KB Output is correct
51 Correct 148 ms 12704 KB Output is correct
52 Correct 143 ms 12624 KB Output is correct
53 Correct 151 ms 13044 KB Output is correct
54 Correct 142 ms 12624 KB Output is correct
55 Correct 145 ms 12768 KB Output is correct
56 Correct 143 ms 12640 KB Output is correct
57 Correct 145 ms 12584 KB Output is correct
58 Correct 143 ms 12600 KB Output is correct
59 Correct 142 ms 12624 KB Output is correct
60 Correct 150 ms 13392 KB Output is correct
61 Correct 143 ms 12460 KB Output is correct
62 Correct 274 ms 9668 KB Output is correct
63 Correct 157 ms 8904 KB Output is correct
64 Correct 164 ms 8892 KB Output is correct
65 Correct 174 ms 10052 KB Output is correct
66 Correct 214 ms 8128 KB Output is correct
67 Correct 261 ms 9892 KB Output is correct
68 Correct 277 ms 8660 KB Output is correct
69 Correct 272 ms 9360 KB Output is correct
70 Correct 269 ms 8716 KB Output is correct
71 Correct 121 ms 9660 KB Output is correct
72 Correct 271 ms 8124 KB Output is correct
73 Correct 280 ms 9332 KB Output is correct
74 Correct 273 ms 8328 KB Output is correct
75 Correct 272 ms 8616 KB Output is correct
76 Correct 133 ms 9924 KB Output is correct
77 Correct 271 ms 9412 KB Output is correct
78 Correct 416 ms 16680 KB Output is correct
79 Correct 298 ms 17996 KB Output is correct
80 Correct 291 ms 16824 KB Output is correct
81 Correct 318 ms 18300 KB Output is correct
82 Correct 353 ms 15800 KB Output is correct
83 Correct 393 ms 16316 KB Output is correct
84 Correct 409 ms 16700 KB Output is correct
85 Correct 411 ms 17412 KB Output is correct
86 Correct 403 ms 16144 KB Output is correct
87 Correct 259 ms 17596 KB Output is correct
88 Correct 411 ms 16620 KB Output is correct
89 Correct 413 ms 16580 KB Output is correct
90 Correct 410 ms 17156 KB Output is correct
91 Correct 408 ms 17220 KB Output is correct
92 Correct 271 ms 19044 KB Output is correct
93 Correct 414 ms 18188 KB Output is correct