結果

問題 No.1301 Strange Graph Shortest Path
ユーザー SSRSSSRS
提出日時 2020-11-27 22:42:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,650 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 181,488 KB
実行使用メモリ 12,092 KB
最終ジャッジ日時 2023-10-09 21:39:37
合計ジャッジ時間 10,561 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 167 ms
9,844 KB
testcase_04 AC 224 ms
12,088 KB
testcase_05 AC 181 ms
11,856 KB
testcase_06 AC 202 ms
10,908 KB
testcase_07 AC 202 ms
11,320 KB
testcase_08 AC 167 ms
9,984 KB
testcase_09 AC 191 ms
10,820 KB
testcase_10 WA -
testcase_11 AC 206 ms
11,256 KB
testcase_12 AC 212 ms
11,176 KB
testcase_13 AC 200 ms
11,052 KB
testcase_14 AC 188 ms
10,380 KB
testcase_15 AC 190 ms
10,896 KB
testcase_16 AC 226 ms
11,880 KB
testcase_17 AC 209 ms
11,620 KB
testcase_18 AC 188 ms
10,576 KB
testcase_19 AC 204 ms
11,212 KB
testcase_20 AC 203 ms
11,148 KB
testcase_21 AC 206 ms
11,428 KB
testcase_22 AC 217 ms
11,512 KB
testcase_23 AC 206 ms
11,164 KB
testcase_24 AC 205 ms
11,428 KB
testcase_25 AC 222 ms
11,440 KB
testcase_26 AC 199 ms
11,476 KB
testcase_27 AC 204 ms
10,996 KB
testcase_28 AC 178 ms
10,528 KB
testcase_29 WA -
testcase_30 AC 216 ms
11,532 KB
testcase_31 AC 214 ms
11,464 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 192 ms
11,640 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 = pr[t];
  }
  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 || pr[v] == w){
            pq2.push(make_pair(dd + get<2>(edge), w));
          } else {
            pq2.push(make_pair(dd + get<1>(edge), w));
          }
        }
      }
    }
  }
  cout << d1[N - 1] + d2[N - 1] << endl;
}
0