結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 162 ms
9,932 KB
testcase_04 AC 208 ms
11,952 KB
testcase_05 AC 178 ms
11,948 KB
testcase_06 AC 195 ms
11,140 KB
testcase_07 AC 186 ms
11,480 KB
testcase_08 AC 162 ms
10,064 KB
testcase_09 AC 191 ms
10,580 KB
testcase_10 WA -
testcase_11 AC 195 ms
10,936 KB
testcase_12 AC 199 ms
11,336 KB
testcase_13 AC 189 ms
11,180 KB
testcase_14 AC 176 ms
10,384 KB
testcase_15 AC 178 ms
11,020 KB
testcase_16 AC 223 ms
11,964 KB
testcase_17 AC 198 ms
11,372 KB
testcase_18 AC 180 ms
10,736 KB
testcase_19 AC 192 ms
11,080 KB
testcase_20 AC 190 ms
11,284 KB
testcase_21 AC 192 ms
11,312 KB
testcase_22 AC 196 ms
11,592 KB
testcase_23 AC 192 ms
11,136 KB
testcase_24 AC 197 ms
11,360 KB
testcase_25 AC 211 ms
11,584 KB
testcase_26 AC 194 ms
11,400 KB
testcase_27 AC 191 ms
10,916 KB
testcase_28 AC 173 ms
10,588 KB
testcase_29 WA -
testcase_30 AC 210 ms
11,256 KB
testcase_31 AC 205 ms
11,640 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 187 ms
11,600 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);
  }
  cout << d1[N - 1] + d2[N - 1] << endl;
}
0