Submission #874259

#TimeUsernameProblemLanguageResultExecution timeMemory
874259alvinggReconstruction Project (JOI22_reconstruction)C++14
100 / 100
1334 ms37556 KiB
#include<bits/stdc++.h> #define pb push_back #define pli pair<int,int> #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=long long; const ll maxn=2e5; const ll inf=1e18; const ll mod=1e9+7; ll n,m; struct edge { ll w,u,v; bool operator<(const edge&o) { return w<o.w; } }e[maxn]; vector<edge>vec; ll lab[maxn]; ll findset(ll x) { return lab[x]<0?x:lab[x]=findset(lab[x]); } void unite(ll u,ll v) { u=findset(u); v=findset(v); if(u==v) return; if(lab[u]>lab[v]) swap(u,v); lab[u]+=lab[v]; lab[v]=u; } void solve() { cin >> n >> m; for(int i=1;i<=m;i++) { cin >> e[i].u >> e[i].v >> e[i].w; } e[0].w=-inf; e[m+1].w=inf; sort(e+1,e+m+1); for(int i=1;i<=m;i++) { ll l=0,r=m+1; for(int j=1;j<=n;j++) lab[j]=-1; for(int j=i+1;j<=m;j++) { unite(e[j].u,e[j].v); if(findset(e[i].u)==findset(e[i].v)) { r=j; break; } } for(int j=1;j<=n;j++) lab[j]=-1; for(int j=i-1;j>=1;j--) { unite(e[j].u,e[j].v); if(findset(e[i].u)==findset(e[i].v)) { l=j; break; } } ll mid=(e[i].w+e[l].w)/2+1; vec.pb({mid,-1,e[i].w}); vec.pb({e[i].w,2,-2*e[i].w}); mid=(e[i].w+e[r].w)/2; vec.pb({mid+1,-1,e[i].w}); } sort(vec.begin(),vec.end()); ll j=0; ll q; cin >> q; ll cnt=0,sum=0; while(q--) { ll x; cin >> x; while(j<vec.size()&&vec[j].w<=x) { cnt+=vec[j].u; sum+=vec[j].v; j++; } cout << cnt*x+sum<<'\n'; } } int main() { fastio //freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }

Compilation message (stderr)

reconstruction.cpp: In function 'void solve()':
reconstruction.cpp:85:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         while(j<vec.size()&&vec[j].w<=x)
      |               ~^~~~~~~~~~~
#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...