Submission #551471

#TimeUsernameProblemLanguageResultExecution timeMemory
551471inksamuraiReconstruction Project (JOI22_reconstruction)C++17
100 / 100
2119 ms34328 KiB
#include <bits/stdc++.h> #define int ll using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define rng(i,x,n) for(int i=x;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define vec(...) vector<__VA_ARGS__> #define _3xxEYjy ios::sync_with_stdio(0),cin.tie(0) typedef long long ll; using pii=pair<int,int>; using vi=vector<int>; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} // e struct dsu{ int n,cmps; vi par,siz; dsu(int m=0){init(m);} void init(int m){ n=m,cmps=m; par=siz=vi(n,0); rep(i,n){ par[i]=i; siz[i]=1; } } void merge(int v,int u){ v=parent(v),u=parent(u); if(v==u)return; cmps--; if(siz[v]<siz[u])swap(v,u); siz[v]+=siz[u]; par[u]=v; } int parent(int v){ return par[v]==v?v:parent(par[v]); } bool same(int v, int u){ return parent(v)==parent(u); } int size(int v=-1){ return (v==-1?cmps:siz[parent(v)]); } }; signed main(){ _3xxEYjy; int n,m; cin>>n>>m; using tpii=pair<int,pii>; vec(tpii) edges; rep(i,m){ int u,v,w; cin>>u>>v>>w; u-=1,v-=1; edges.pb({w,{u,v}}); } sort(edges.begin(),edges.end()); const int inf=1e10; vec(tpii) evts; rep(i,m){ dsu uf(n); int r=inf; rng(j,i+1,m){ uf.merge(edges[j].se.fi,edges[j].se.se); if(uf.same(edges[i].se.fi,edges[i].se.se)){ r=edges[j].fi; break; } } uf.init(n); int l=-inf; per(j,i){ uf.merge(edges[j].se.fi,edges[j].se.se); if(uf.same(edges[i].se.fi,edges[i].se.se)){ l=edges[j].fi; break; } } int w=edges[i].fi; evts.pb({l==-inf?-1:(l+w)/2+(l+w)%2,{-1,+w}}); evts.pb({w,{+2,-2ll*w}}); evts.pb({r==inf?inf:(r+w)/2+(r+w)%2,{-1,+w}}); } sort(evts.begin(),evts.end(),[&](tpii l,tpii r){ if(l.fi!=r.fi){ return l.fi<r.fi; }else{ return l.se.fi<r.se.fi; } }); int q; cin>>q; int i=-1; pii p={0,0}; rep(_,q){ int x; cin>>x; while(i+1<sz(evts) and evts[i+1].fi<=x){ i+=1; // print(evts[i].fi,evts[i].se.fi,evts[i].se.se); p.fi+=evts[i].se.fi; p.se+=evts[i].se.se; } // print(p.fi,p.se); cout<<p.fi*x+p.se<<"\n"; // break; } // return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...