Submission #959002

#TimeUsernameProblemLanguageResultExecution timeMemory
959002maxFedorchukEvacuation plan (IZhO18_plan)C++17
0 / 100
932 ms524288 KiB
#include <bits/stdc++.h> using namespace std; const int MX=5e5+10; const int INF=1e9; vector < pair < int , int > > mas[MX]; vector < pair < int , int > > zap[MX]; vector < int > pol[MX]; int ld[MX],sz[MX]; int ans[MX]; int vid[MX],vis[MX]; void ob(int a,int b,int vg) { a=ld[a]; b=ld[b]; if(a==b) { return; } if(sz[a]<sz[b]) { swap(a,b); } while(!pol[b].empty()) { int zr=pol[b].back(); pol[b].pop_back(); pol[a].push_back(zr); ld[zr]=a; for(auto [vr,in]:zap[zr]) { if(ld[zr]==ld[vr]) { ans[in]=max(ans[in],vg); } } } } int main() { //cin.tie(0); //ios_base::sync_with_stdio(0); int n,m,k,kzp; cin>>n>>m; int a,b,w; for(int i=1;i<=m;i++) { cin>>a>>b>>w; mas[a].push_back({b,w}); mas[b].push_back({a,w}); } fill(vid+1,vid+1+n,INF); priority_queue < pair < int , int > , vector < pair < int , int > > , greater < pair < int , int > > > q; cin>>k; for(int i=1;i<=k;i++) { cin>>a; vid[a]=0; q.push({0,a}); } while(!q.empty()) { int zar=q.top().second; q.pop(); if(vis[zar]) { continue; } vis[zar]=1; for(auto [vr,dr]:mas[zar]) { if((vid[zar]+dr)<vid[vr]) { vid[vr]=vid[zar]+dr; q.push({vid[vr],vr}); } } } for(int i=1;i<=n;i++) { cout<<vid[i]<<" "; } cout<<"\n"; vector < pair < int , int > > alv; for(int i=1;i<=n;i++) { alv.push_back({vid[i],i}); ld[i]=i; sz[i]=1; pol[i].push_back(i); } sort(alv.begin(),alv.end()); reverse(alv.begin(),alv.end()); cin>>kzp; for(int i=1;i<=kzp;i++) { cin>>a>>b; zap[a].push_back({b,i}); zap[b].push_back({a,i}); } set < int > vvv; for(auto [zn,vr]:alv) { vvv.insert(vr); for(auto u:mas[vr]) { if(vvv.find(u.first)!=vvv.end()) { ob(vr,u.first,zn); } } } for(int i=1;i<=kzp;i++) { cout<<ans[i]<<"\n"; } 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...