結果

問題 No.1301 Strange Graph Shortest Path
ユーザー SSRSSSRS
提出日時 2020-11-27 21:57:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,651 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 180,472 KB
実行使用メモリ 11,956 KB
最終ジャッジ日時 2023-10-10 21:41:12
合計ジャッジ時間 10,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 164 ms
9,924 KB
testcase_04 AC 221 ms
11,836 KB
testcase_05 AC 183 ms
11,804 KB
testcase_06 AC 200 ms
10,944 KB
testcase_07 AC 196 ms
11,532 KB
testcase_08 AC 167 ms
9,856 KB
testcase_09 AC 190 ms
10,644 KB
testcase_10 WA -
testcase_11 AC 210 ms
10,948 KB
testcase_12 AC 210 ms
11,352 KB
testcase_13 AC 198 ms
11,180 KB
testcase_14 AC 188 ms
10,252 KB
testcase_15 AC 190 ms
10,860 KB
testcase_16 AC 223 ms
11,956 KB
testcase_17 AC 204 ms
11,524 KB
testcase_18 AC 186 ms
10,536 KB
testcase_19 AC 203 ms
11,132 KB
testcase_20 AC 202 ms
11,488 KB
testcase_21 AC 203 ms
11,460 KB
testcase_22 AC 210 ms
11,616 KB
testcase_23 AC 201 ms
11,332 KB
testcase_24 AC 205 ms
11,380 KB
testcase_25 AC 223 ms
11,516 KB
testcase_26 AC 199 ms
11,428 KB
testcase_27 AC 204 ms
10,844 KB
testcase_28 AC 179 ms
10,608 KB
testcase_29 WA -
testcase_30 AC 218 ms
11,256 KB
testcase_31 AC 217 ms
11,620 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 186 ms
11,660 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, N - 1));
  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 (w == pr[v]){
            pq2.push(make_pair(dd + get<2>(edge), w));
          } else {
            pq2.push(make_pair(dd + get<1>(edge), w));
          }
        }
      }
    }
  }
  cout << d1[N - 1] + d2[0] << endl;
}
0