結果

問題 No.1601 With Animals into Institute
ユーザー tnakao0123tnakao0123
提出日時 2021-07-12 15:04:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 3,000 ms
コード長 1,596 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 99,852 KB
実行使用メモリ 15,984 KB
最終ジャッジ日時 2023-09-14 20:34:45
合計ジャッジ時間 6,807 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,064 KB
testcase_01 AC 3 ms
6,088 KB
testcase_02 AC 2 ms
5,936 KB
testcase_03 AC 5 ms
6,252 KB
testcase_04 AC 5 ms
6,208 KB
testcase_05 AC 5 ms
6,204 KB
testcase_06 AC 264 ms
15,704 KB
testcase_07 AC 268 ms
15,976 KB
testcase_08 AC 256 ms
15,744 KB
testcase_09 AC 255 ms
15,916 KB
testcase_10 AC 260 ms
15,680 KB
testcase_11 AC 261 ms
15,984 KB
testcase_12 AC 253 ms
15,704 KB
testcase_13 AC 254 ms
15,796 KB
testcase_14 AC 260 ms
15,888 KB
testcase_15 AC 267 ms
15,800 KB
testcase_16 AC 262 ms
15,772 KB
testcase_17 AC 260 ms
15,768 KB
testcase_18 AC 5 ms
6,392 KB
testcase_19 AC 6 ms
6,256 KB
testcase_20 AC 6 ms
6,344 KB
testcase_21 AC 5 ms
6,372 KB
testcase_22 AC 5 ms
6,512 KB
testcase_23 AC 5 ms
6,308 KB
testcase_24 AC 6 ms
6,332 KB
testcase_25 AC 6 ms
6,316 KB
testcase_26 AC 6 ms
6,240 KB
testcase_27 AC 3 ms
6,028 KB
testcase_28 AC 3 ms
5,956 KB
testcase_29 AC 3 ms
6,200 KB
testcase_30 AC 2 ms
5,948 KB
testcase_31 AC 3 ms
6,020 KB
testcase_32 AC 2 ms
5,976 KB
testcase_33 AC 3 ms
5,952 KB
testcase_34 AC 2 ms
5,948 KB
testcase_35 AC 3 ms
6,088 KB
testcase_36 AC 2 ms
5,936 KB
testcase_37 AC 2 ms
6,000 KB
testcase_38 AC 3 ms
5,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1601.cc:  No.1601 With Animals into Institute - 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 = 200000;
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], xs[MAX_M];
vpii nbrs[MAX_N];
ll ds[MAX_N * 2];

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d%d%d", &a, &b, cs + i, xs + i);
    a--, b--;
    nbrs[a].push_back(pii(b, i));
    nbrs[b].push_back(pii(a, i));
  }

  int st = (n - 1) << 1;
  fill(ds, ds + n * 2, LINF);
  ds[st] = 0;

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

  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll ud = -u.first;
    if (ds[u.second] != ud) continue;

    int ui = (u.second >> 1), ux = (u.second & 1);
    for (auto ve: nbrs[ui]) {
      int vi = ve.first, ei = ve.second;
      ll vd = ud + cs[ei];
      int vx = (ux | xs[ei]), v = ((vi << 1) | vx);
      if (ds[v] > vd) {
	ds[v] = vd;
	q.push(pli(-vd, v));
      }
    }
  }

  for (int i = 0; i < n - 1; i++)
    printf("%lld\n", ds[(i << 1) | 1]);

  return 0;
}
0