結果
| 問題 |
No.1301 Strange Graph Shortest Path
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-27 22:29:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,750 bytes |
| コンパイル時間 | 1,883 ms |
| コンパイル使用メモリ | 188,372 KB |
| 実行使用メモリ | 23,440 KB |
| 最終ジャッジ日時 | 2024-07-26 19:50:49 |
| 合計ジャッジ時間 | 11,370 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}
//dijkstraをする。Gは<to, cost>の配列。dは結果。vは始点。
void dijkstra(vector<vector<llll>> &G, vector<ll> &d, vector<ll> &pre, ll v){
fill(ALL(d), INF / 2);
d[v] = 0;
priority_queue<llll, vector<llll>, greater<llll>> q;
q.push(make_pair(0, v));
while(!q.empty()){
auto p = q.top(); q.pop();
auto pv = p.second;
if(d[pv] < p.first) continue; //p.secondへの距離が更新済みならスルー
for (auto next : G[pv]) {
if(d[pv] + next.second >= d[next.first]) continue;
d[next.first] = d[pv] + next.second;
pre[next.first] = pv;
q.push(make_pair(d[next.first], next.first));
}
}
}
int main(){
ll N, M;
cin >> N >> M;
vector<vector<llll>> G(N);
map<llll, ll> m;
vector<ll> u(M), v(M), c(M), d(M);
for (ll i = 0; i < M; i++) {
cin >> u[i] >> v[i] >> c[i] >> d[i];
u[i]--; v[i]--;
G[u[i]].push_back({v[i], c[i]});
G[v[i]].push_back({u[i], c[i]});
m[{u[i], v[i]}] = i;
}
vector<ll> dis(N), pre(N);
dijkstra(G, dis, pre, 0);
ll tmp = N-1;
ll ans = dis[N-1];
for (ll i = 0; i < N; i++) {
G[i].clear();
}
vector<ll> ind;
while(tmp != 0){
ll ttmp = pre[tmp];
bool ch = false;
if(ttmp < tmp){
swap(ttmp, tmp);
ch = true;
}
ind.push_back(m[{tmp, ttmp}]);
if(ch == false){
swap(ttmp, tmp);
}
}
int indd = 0;
sort(ALL(ind));
for (int i = 0; i < M; i++) {
if(ind[indd] == i){
G[u[i]].push_back({v[i], d[i]});
G[v[i]].push_back({u[i], d[i]});
indd++;
}
else{
G[u[i]].push_back({v[i], c[i]});
G[v[i]].push_back({u[i], c[i]});
}
}
// for (auto vv : m){
// printf("%lld %lld %lld\n", vv.first.first, vv.first.second, vv.second);
// }
// for (int i = 0; i < N; i++) {
// cout << i << " " << pre[i] << endl;
// }
// for (int i = 0; i < ind.size(); i++) {
// cout << ind[i] << endl;
// }
dijkstra(G, dis, pre, N-1);
ans += dis[0];
printf("%lld\n", ans);
}