結果
| 問題 |
No.1301 Strange Graph Shortest Path
|
| コンテスト | |
| ユーザー |
snow39
|
| 提出日時 | 2020-11-27 22:23:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,127 bytes |
| コンパイル時間 | 1,731 ms |
| コンパイル使用メモリ | 116,868 KB |
| 実行使用メモリ | 21,224 KB |
| 最終ジャッジ日時 | 2024-07-26 19:45:03 |
| 合計ジャッジ時間 | 8,875 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 5 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
int N,M;
vector<vector<pair<int,ll>>> cg;
vector<vector<pair<int,ll>>> dg;
const ll INF=1e18;
map<pair<int,int>,int> mp;
ll dijkstra(vector<int> &path){
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> PQ;
PQ.push(mkp(0,0));
vector<ll> dist(N,INF);
vector<int> prev(N,-1);
dist[0]=0;
while(!PQ.empty()){
auto f=PQ.top();
PQ.pop();
int now=f.second;
ll d=f.first;
if(dist[now]<d) continue;
for(auto e:cg[now]){
int to=e.first;
ll cost=e.second;
if(mp.count(minmax(now,to))) continue;
if(dist[to]>dist[now]+cost){
prev[to]=now;
dist[to]=dist[now]+cost;
PQ.push(mkp(dist[to],to));
}
}
for(auto e:dg[now]){
int to=e.first;
ll cost=e.second;
if(mp.count(minmax(now,to))==false) continue;
if(dist[to]>dist[now]+cost){
prev[to]=now;
dist[to]=dist[now]+cost;
PQ.push(mkp(dist[to],to));
}
}
}
int now=N-1;
while(prev[now]!=-1){
path.push_back(now);
now=prev[now];
}
path.push_back(now);
reverse(all(path));
return dist[N-1];
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin>>N>>M;
cg.resize(N);
dg.resize(N);
rep(i,M){
int a,b,c,d;
cin>>a>>b>>c>>d;
a--;b--;
cg[a].push_back(mkp(b,c));
cg[b].push_back(mkp(a,c));
dg[a].push_back(mkp(b,d));
dg[b].push_back(mkp(a,d));
}
vector<int> onepath;
ll ares=dijkstra(onepath);
for(int i=0;i+1<onepath.size();i++) mp[minmax(onepath[i],onepath[i+1])]=1;
vector<int> twopath;
ll bres=dijkstra(twopath);
cout<<ares+bres<<endl;
return 0;
}
snow39