結果

問題 No.1301 Strange Graph Shortest Path
ユーザー SSRSSSRS
提出日時 2020-11-27 22:10:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,764 bytes
コンパイル時間 1,910 ms
コンパイル使用メモリ 181,172 KB
実行使用メモリ 12,296 KB
最終ジャッジ日時 2023-10-10 21:43:02
合計ジャッジ時間 9,577 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 WA -
testcase_03 AC 155 ms
9,872 KB
testcase_04 AC 194 ms
11,812 KB
testcase_05 AC 170 ms
11,888 KB
testcase_06 AC 172 ms
11,124 KB
testcase_07 AC 172 ms
11,140 KB
testcase_08 AC 155 ms
10,048 KB
testcase_09 AC 164 ms
10,532 KB
testcase_10 WA -
testcase_11 AC 180 ms
11,076 KB
testcase_12 AC 182 ms
11,192 KB
testcase_13 AC 180 ms
11,032 KB
testcase_14 AC 164 ms
10,332 KB
testcase_15 AC 169 ms
10,896 KB
testcase_16 AC 196 ms
12,268 KB
testcase_17 AC 184 ms
11,372 KB
testcase_18 AC 168 ms
10,736 KB
testcase_19 AC 179 ms
11,144 KB
testcase_20 AC 172 ms
11,348 KB
testcase_21 AC 180 ms
11,328 KB
testcase_22 AC 173 ms
11,668 KB
testcase_23 AC 180 ms
11,268 KB
testcase_24 AC 176 ms
11,444 KB
testcase_25 AC 200 ms
11,436 KB
testcase_26 AC 177 ms
11,540 KB
testcase_27 AC 179 ms
10,840 KB
testcase_28 AC 168 ms
10,540 KB
testcase_29 WA -
testcase_30 AC 188 ms
11,340 KB
testcase_31 AC 188 ms
11,632 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 168 ms
11,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<tuple<int, int, int>>> E(N);
  for (int i = 0; i < M; i++){
    int u, v, c, d;
    cin >> u >> v >> c >> d;
    u--;
    v--;
    E[u].push_back(make_tuple(v, c, d));
    E[v].push_back(make_tuple(u, c, d));
  }
  vector<long long> d1(N, -1);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq1;
  pq1.push(make_pair(0, 0));
  while (!pq1.empty()){
    long long dd = pq1.top().first;
    int v = pq1.top().second;
    pq1.pop();
    if (d1[v] == -1){
      d1[v] = dd;
      for (auto edge : E[v]){
        int w = get<0>(edge);
        if (d1[w] == -1){
          pq1.push(make_pair(dd + get<1>(edge), w));
        }
      }
    }
  }
  vector<int> pr(N, -1);
  int t = N - 1;
  while (t > 0){
    for (auto edge : E[t]){
      int w = get<0>(edge);
      if (d1[w] == d1[t] - get<1>(edge)){
        pr[t] = w;
        t = w;
        break;
      }
    }
  }
  vector<long long> d2(N, -1);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq2;
  pq2.push(make_pair(0, 0));
  while (!pq2.empty()){
    long long dd = pq2.top().first;
    int v = pq2.top().second;
    pq2.pop();
    if (d2[v] == -1){
      d2[v] = dd;
      for (auto edge : E[v]){
        int w = get<0>(edge);
        if (d2[w] == -1){
          if (pr[w] == v){
            pq2.push(make_pair(dd + get<2>(edge), w));
          } else {
            pq2.push(make_pair(dd + get<1>(edge), w));
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++){
    assert(d1[i] != -1);
    assert(d2[i] != -1);
    assert(d1[i] <= d2[i]);
  }
  cout << d1[N - 1] + d2[N - 1] << endl;
}
0