結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー |
![]() |
提出日時 | 2021-04-19 22:42:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,880 bytes |
コンパイル時間 | 1,835 ms |
コンパイル使用メモリ | 184,912 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-07-04 05:09:58 |
合計ジャッジ時間 | 9,693 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 WA * 5 |
ソースコード
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll=long long; using Graph=vector<vector<pair<int,int>>>; #define MAX 200003 #define MOD 1000000007 #define INF 1000000000000000000 int main(){ int N,M; cin>>N>>M; vector<int> u(M),v(M); vector<ll> c(M),d(M); for(int i=0;i<M;i++){ cin>>u[i]>>v[i]>>c[i]>>d[i]; u[i]--; v[i]--; } Graph G(N); for(int i=0;i<M;i++){ G[u[i]].push_back(make_pair(v[i],i)); G[v[i]].push_back(make_pair(u[i],i)); } vector<ll> dist(N,INF); dist[0]=0; priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq; pq.push(make_pair(dist[0],0)); while(!pq.empty()){ int v=pq.top().second; ll l=pq.top().first; pq.pop(); if(l>dist[v]){ continue; } for(auto p:G[v]){ int nv=p.first; int e=p.second; if(dist[v]+c[e]<dist[nv]){ dist[nv]=dist[v]+c[e]; pq.push(make_pair(dist[nv],nv)); } } } int x=N-1; vector<bool> used(M,false); while(x!=0){ for(auto p:G[x]){ int nv=p.first; int e=p.second; if(dist[x]==dist[nv]+c[e]){ x=nv; used[e]=true; break; } } } ll ans=dist[N-1]; for(int i=0;i<N-1;i++){ dist[i]=INF; } dist[N-1]=0; pq.push(make_pair(dist[N-1],N-1)); while(!pq.empty()){ int v=pq.top().second; ll l=pq.top().first; pq.pop(); if(l>dist[v]){ continue; } for(auto p:G[v]){ int nv=p.first; int e=p.second; if(used[e]==true){ if(dist[v]+d[e]<dist[nv]){ dist[nv]=dist[v]+d[e]; pq.push(make_pair(dist[nv],nv)); } }else{ if(dist[v]+c[e]<dist[nv]){ dist[nv]=dist[v]+c[e]; pq.push(make_pair(dist[nv],nv)); } } } } ans+=dist[0]; cout<<ans<<endl; }