結果
| 問題 |
No.1301 Strange Graph Shortest Path
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-27 22:53:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,944 bytes |
| コンパイル時間 | 2,448 ms |
| コンパイル使用メモリ | 193,592 KB |
| 実行使用メモリ | 32,736 KB |
| 最終ジャッジ日時 | 2024-07-26 20:07:32 |
| 合計ジャッジ時間 | 16,963 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 5 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;
int n = 100005;
int m;
vector<map<ll,ll>> graph(n);
using p = pair<pll,int>;
vector<ll> before(n);
vector<ll> Dijkstra(int start){
vector<bool> seen(n,false);
vector<ll> shortest(n,LINF);
priority_queue<p,vector<p>,greater<p>> pq;
pq.push(p(pll{0,start},-1));
while(!pq.empty()){
ll dist = pq.top().first.first;
int node = pq.top().first.second;
int b = pq.top().second;
pq.pop();
if(seen[node]) continue;
shortest[node] = dist;
before[node] = b;
seen[node] = true;
for(auto next:graph[node]){
int next_node = next.first;
ll next_cost = next.second;
if(seen[next_node]) continue;
pq.push(p(pll{next_cost + dist,next_node},node));
}
}
return shortest;
}
int main(){
cin >> n >> m;
map<P,ll> dist;
rep(i,m){
int u,v,c,d;
cin >> u >> v >> c >> d;
--u;--v;
graph[u][v] = c;
graph[v][u] = c;
if(u>v) swap(u,v);
dist[P(u,v)] = d;
}
//rep(i,n){
//for(auto p:graph[i])
//}
vector<ll> res = Dijkstra(0);
//rep(i,n) cout << res[i] << " ";
//cout << endl;
int now = n-1;
while(now > 0){
int a = now;
int b = before[now];
graph[a][b] = dist[P(min(a,b),max(a,b))];
graph[b][a] = graph[a][b];
now = b;
//cout << now << endl;
}
vector<ll> ret = Dijkstra(n-1);
cout << res[n-1] + ret[0] << endl;
return 0;
}