Submission #647000

#TimeUsernameProblemLanguageResultExecution timeMemory
647000inksamuraiCeste (COCI17_ceste)C++17
0 / 160
471 ms764 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,c,n) for(int i=c;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 _3SJjfN1 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 signed main(){ _3SJjfN1; int n,m; cin>>n>>m; using T=pair<pii,int>; vec(vec(T)) adj(n); vec(pii) es; rep(i,m){ int u,v,c0,c1; cin>>u>>v>>c0>>c1; u-=1,v-=1; adj[u].pb(T(pii(c0,c1),v)); adj[v].pb(T(pii(c0,c1),u)); es.pb(pii(c0,c1)); } const int inf=1e18; vi pns(n,inf); auto dijkstra=[&](int p,int q)->void{ struct state{ int x,y,p,q,v; state(int _x=0,int _y=0,int _p=0,int _q=0,int _v=0): x(_x),y(_y),p(_p),q(_q),v(_v){}; bool operator<(const state&a)const{ return pii((x+p)*(y+q),v)>pii((a.x+p)*(a.y+q),a.v); } }; priority_queue<state> pq; pq.push(state(0,0,p,q,0)); vec(pii) d(n,{inf,inf}); d[0]=pii(0,0); while(sz(pq)){ auto top=pq.top(); int v=top.v,x=top.x,y=top.y; pq.pop(); if(d[v]!=pii(x,y)) continue; for(auto e:adj[v]){ int c0=e.fi.fi,c1=e.fi.se,u=e.se; // if(v==0) print(u); if(d[u].fi==inf or (d[u].fi+p)*(d[u].se+q)>(x+c0+p)*(y+c1+q)){ d[u]={x+c0,y+c1}; pq.push(state(x+c0,y+c1,p,q,u)); } } } rep(v,n){ pns[v]=min(pns[v],d[v].fi*d[v].se); } }; // dijkstra(3,2); for(auto p:es){ print(p.fi,p.se); dijkstra(p.fi,p.se); } rng(v,1,n){ print(pns[v]==inf?-1:pns[v]); } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...