結果

問題 No.1344 Typical Shortest Path Sum
ユーザー tarattata1tarattata1
提出日時 2021-01-16 14:25:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,170 bytes
コンパイル時間 1,344 ms
コンパイル使用メモリ 104,804 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-05 16:44:18
合計ジャッジ時間 4,917 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
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 #

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <ctime>
#pragma warning(disable:4996) 

//#define ATCODER
#ifdef ATCODER
#include <atcoder/all>
#endif

typedef long long ll;
typedef unsigned long long ull;
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;
#ifdef ATCODER
using namespace atcoder;
#endif

vector<vector<pair<int,int> > > g;   // to, cost

typedef pair<ll, int> P;
vector<ll> dijkstra(int s, const vector<vector<pair<int, int> > >& G) {
    priority_queue< P, vector<P>, greater<P> > que;
    vector<ll> d(G.size(), LINF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        int curr = que.top().second;
        ll  dcurr = que.top().first;
        que.pop();
        if (d[curr] < dcurr) continue;
        int i;
        for (i = 0; i < (int)G[curr].size(); i++) {
            int next = G[curr][i].first;
            ll  dist = G[curr][i].second;
            if (d[next] > d[curr] + dist) {
                d[next] = d[curr] + dist;
                que.push(P(d[next], next));
            }
        }
    }
    return d;
}

void solve()
{
    int n, m;
    scanf("%d%d", &n, &m);
    g.resize(n);
    int i, j;
    for (i = 0; i < m; i++) {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w); u--; v--;
        g[u].push_back(make_pair(v, w));
    }

    vector<vector<ll> > dist(n);
    
    for (i = 0; i < n; i++) {
        dist[i] = dijkstra(i, g);   
        ll ans = 0;
        for (j = 0; j < n; j++) {
            if (dist[i][j] < LINF) ans += dist[i][j];
        }
        printf("%lld\n", ans);
    }


    return;
}

int main()
{
#if 1
    solve();
#else
    int T, t;
    cin >> T;
    for (t = 0; t < T; t++) {
        //cout << "Case #" << t + 1 << ": ";
        solve();
    }
#endif
    return 0;
}
0