제출 #501538

#제출 시각아이디문제언어결과실행 시간메모리
501538FEDIKUSRobot (JOI21_ho_t4)C++17
0 / 100
1018 ms60472 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define xx first #define yy second #define ff(i,s,f) for(ll i=s;i<f;i++) #define fb(i,s,f) for(ll i=(s)-1;i>=f;i--) #define ffi(i,s,f) for(ll i=s;i<=f;i++) #define fbi(i,s,f) for(ll i=s;i>=f;i--) #define srt(a) sort(a.begin(),a.end()); #define srtg(a,ll) sort(a.begin(),a.end(),greater<ll>()) #define lb(a,x) lower_bound(a.begin(),a.end(),x) #define ub(a,x) upper_bound(a.begin(),a.end(),x) #define fnd(a,x) find(a.begin(),a.end(),x) #define vstart auto startt=chrono::system_clock::now() #define vend auto endd=chrono::system_clock::now() #define vvreme chrono::duration<double> vremee=endd-startt #define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef pair<ll,ll> pii; typedef pair<ll,ll> pll; typedef string str; const ll maxn=2e5+10; struct edge{ ll c,p,to,koji,dist=-1; edge(ll _c,ll _p,ll _to,ll _koji){ c=_c; p=_p; to=_to; koji=_koji; } bool operator <(edge b){ return vector<ll>({this->c,this->p})<vector<ll>({b.c,b.p}); } }; ll n; vector<edge> g[maxn]; map<ll,ll> sum[maxn]; ll dijkstra(ll poc){ vector<ll> dist(maxn,-1); priority_queue<pair<ll,pii> ,vector<pair<ll,pii> >, greater<pair<ll,pii> > > pq; pq.push({0,{poc,-1}}); dist[poc]=0; while(!pq.empty()){ auto tren=pq.top(); pq.pop(); if(tren.yy.yy==-1){ if(tren.xx!=dist[tren.yy.xx]) continue; }else{ if(tren.xx!=g[tren.yy.xx][tren.yy.yy].dist) continue; } if(tren.yy.yy==-1){ for(auto i:g[tren.yy.xx]){ ///normalan if(dist[i.to]>min(tren.xx+i.p,tren.xx+sum[tren.yy.xx][i.c]-i.p) || dist[i.to]==-1){ dist[i.to]=min(tren.xx+i.p,tren.xx+sum[tren.yy.xx][i.c]-i.p); pq.push({dist[i.to],{i.to,-1}}); } ///ujeban if(g[i.to][i.koji].dist>tren.xx+i.p || g[i.to][i.koji].dist==-1){ g[i.to][i.koji].dist=tren.xx+i.p; pq.push({g[i.to][i.koji].dist,{i.to,i.koji}}); } } }else{ ll naj=lower_bound(g[tren.yy.xx].begin(),g[tren.yy.xx].end(),edge(g[tren.yy.xx][tren.yy.yy].c+1,-1,-1,-1))-g[tren.yy.xx].begin()-1; if(naj==tren.yy.yy) naj--; if(naj<0 || g[tren.yy.xx][naj].c!=g[tren.yy.xx][tren.yy.yy].c) continue; auto &grana=g[tren.yy.xx][naj]; ll c=g[tren.yy.xx][tren.yy.yy].c; if(g[grana.to][grana.koji].dist>tren.xx+sum[tren.yy.xx][c]-grana.p-g[tren.yy.xx][tren.yy.yy].p || g[grana.to][grana.koji].dist==-1){ g[grana.to][grana.koji].dist=tren.xx+sum[tren.yy.xx][c]-grana.p-g[tren.yy.xx][tren.yy.yy].p; pq.push({g[grana.to][grana.koji].dist,{grana.to,grana.koji}}); } if(dist[grana.to]>g[grana.to][grana.koji].dist || dist[grana.to]==-1){ dist[grana.to]=g[grana.to][grana.koji].dist; pq.push({dist[grana.to],{grana.to,-1}}); } } } return dist[n]; } void solve(){ ll m; cin>>n>>m; for(ll i=0;i<m;i++){ ll a,b,c,p; cin>>a>>b>>c>>p; g[a].pb(edge(c,p,b,-1)); sum[a][c]+=p; g[b].pb(edge(c,p,a,-1)); sum[b][c]+=p; } for(ll i=1;i<=n;i++) sort(g[i].begin(),g[i].end()); for(ll i=1;i<=n;i++){ for(auto &j:g[i]){ j.koji=lower_bound(g[j.to].begin(),g[j.to].end(),edge(j.c,j.p,i,-1))-g[j.to].begin(); } } cout<<dijkstra(1); } int main(){ ios; ll t=1; //cin>>t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...