結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 153 ms
10,080 KB
testcase_04 AC 188 ms
11,820 KB
testcase_05 AC 173 ms
11,788 KB
testcase_06 AC 175 ms
11,124 KB
testcase_07 AC 176 ms
11,136 KB
testcase_08 AC 155 ms
10,068 KB
testcase_09 AC 164 ms
10,592 KB
testcase_10 WA -
testcase_11 AC 181 ms
11,276 KB
testcase_12 AC 187 ms
11,288 KB
testcase_13 AC 179 ms
10,976 KB
testcase_14 AC 163 ms
10,380 KB
testcase_15 AC 167 ms
11,000 KB
testcase_16 AC 192 ms
11,904 KB
testcase_17 AC 186 ms
11,716 KB
testcase_18 AC 167 ms
10,784 KB
testcase_19 AC 179 ms
11,164 KB
testcase_20 AC 175 ms
11,288 KB
testcase_21 AC 187 ms
11,312 KB
testcase_22 AC 182 ms
11,672 KB
testcase_23 AC 185 ms
11,220 KB
testcase_24 AC 178 ms
11,512 KB
testcase_25 AC 190 ms
11,464 KB
testcase_26 AC 180 ms
11,480 KB
testcase_27 AC 185 ms
10,896 KB
testcase_28 AC 169 ms
10,396 KB
testcase_29 WA -
testcase_30 AC 190 ms
11,548 KB
testcase_31 AC 194 ms
11,488 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 172 ms
11,528 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));
          }
        }
      }
    }
  }
  cout << d1[N - 1] + d2[N - 1] << endl;
}
0