結果

問題 No.1301 Strange Graph Shortest Path
ユーザー tnakao0123tnakao0123
提出日時 2020-11-28 01:07:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,913 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 100,652 KB
実行使用メモリ 12,260 KB
最終ジャッジ日時 2023-10-09 23:10:40
合計ジャッジ時間 5,525 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,084 KB
testcase_01 AC 2 ms
6,044 KB
testcase_02 WA -
testcase_03 AC 62 ms
10,132 KB
testcase_04 AC 85 ms
12,116 KB
testcase_05 AC 59 ms
10,472 KB
testcase_06 AC 109 ms
11,348 KB
testcase_07 AC 81 ms
10,864 KB
testcase_08 AC 60 ms
10,128 KB
testcase_09 AC 64 ms
11,184 KB
testcase_10 WA -
testcase_11 AC 82 ms
11,496 KB
testcase_12 AC 72 ms
11,452 KB
testcase_13 AC 78 ms
11,164 KB
testcase_14 AC 78 ms
11,060 KB
testcase_15 AC 58 ms
10,780 KB
testcase_16 AC 90 ms
12,100 KB
testcase_17 AC 82 ms
11,500 KB
testcase_18 AC 71 ms
10,604 KB
testcase_19 AC 63 ms
11,460 KB
testcase_20 AC 82 ms
11,680 KB
testcase_21 AC 79 ms
11,364 KB
testcase_22 AC 73 ms
11,872 KB
testcase_23 AC 63 ms
11,072 KB
testcase_24 AC 83 ms
12,048 KB
testcase_25 AC 70 ms
11,756 KB
testcase_26 AC 71 ms
11,084 KB
testcase_27 AC 72 ms
11,444 KB
testcase_28 AC 61 ms
10,256 KB
testcase_29 WA -
testcase_30 AC 84 ms
11,616 KB
testcase_31 AC 80 ms
11,912 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 66 ms
11,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1301.cc:  No.1301 Strange Graph Shortest Path - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<pii> vpii;

/* global variables */

int cs[MAX_M], ds[MAX_M], wis[MAX_M];
vpii nbrs[MAX_N];
ll dists[MAX_N];
pii ps[MAX_N];

/* subroutines */

ll dijkstra(int n, int st, int gl) {
  fill(dists, dists + n, LINF);
  dists[st] = 0, ps[0] = pii(-1, -1);

  priority_queue<pli> q;
  q.push(pli(0, st));

  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll ud = -u.first;
    int ui = u.second;
    if (dists[ui] != ud) continue;
    if (ui == gl) break;

    vpii &nbru = nbrs[ui];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int vi = vit->first, ei = vit->second;
      ll vd = ud + wis[ei];
      if (dists[vi] > vd) {
	dists[vi] = vd, ps[vi] = pii(ui, ei);
	q.push(pli(-vd, vi));
      }
    }
  }

  return dists[gl];
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d%d%d", &u, &v, cs + i, ds + i);
    u--, v--;
    nbrs[u].push_back(pii(v, i));
    nbrs[v].push_back(pii(u, i));
  }
  copy(cs, cs + m, wis);

  ll d0 = dijkstra(n, 0, n - 1);
  //printf("d0=%lld\n", d0);

  for (int u = n - 1; u > 0;) {
    pli p = ps[u];
    wis[p.second] = ds[p.second];
    u = p.first;
  }

  ll d1 = dijkstra(n, n - 1, 0);

  printf("%lld\n", d0 + d1);
  return 0;
}
0