結果

問題 No.1344 Typical Shortest Path Sum
ユーザー tnakao0123tnakao0123
提出日時 2021-01-19 18:21:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,579 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 96,768 KB
実行使用メモリ 7,964 KB
最終ジャッジ日時 2023-08-22 15:21:14
合計ジャッジ時間 7,756 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,500 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 1 ms
4,380 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
4,380 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 5 ms
4,376 KB
testcase_61 AC 1 ms
4,376 KB
testcase_62 TLE -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1344.cc:  No.1344 Typical Shortest Path Sum - 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 = 100;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef vector<pil> vpil;

/* global variables */

vpil nbrs[MAX_N];
ll ds[MAX_N];

/* subroutines */

void dijkstra(int n, int st) {
  fill(ds, ds + n, LINF);
  ds[st] = 0;

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

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

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

/* main */

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

  for (int i = 0; i < m; i++) {
    int u, v;
    ll d;
    scanf("%d%d%lld", &u, &v, &d);
    u--, v--;
    nbrs[u].push_back(pil(v, d));
  }

  for (int st = 0; st < n; st++) {
    dijkstra(n, st);

    ll sum = 0;
    for (int i = 0; i < n; i++)
      if (ds[i] < LINF) sum += ds[i];
    printf("%lld\n", sum);
  }

  return 0;
}
0