結果

問題 No.1344 Typical Shortest Path Sum
ユーザー maguromaguro
提出日時 2021-01-13 20:25:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,993 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 198,424 KB
実行使用メモリ 5,596 KB
最終ジャッジ日時 2023-08-17 15:24:29
合計ジャッジ時間 4,553 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,376 KB
testcase_01 AC 3 ms
5,276 KB
testcase_02 AC 3 ms
5,596 KB
testcase_03 AC 3 ms
5,364 KB
testcase_04 AC 3 ms
5,308 KB
testcase_05 AC 3 ms
5,320 KB
testcase_06 AC 3 ms
5,284 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 3 ms
5,308 KB
testcase_10 AC 3 ms
5,284 KB
testcase_11 AC 3 ms
5,328 KB
testcase_12 WA -
testcase_13 AC 3 ms
5,300 KB
testcase_14 AC 3 ms
5,308 KB
testcase_15 AC 3 ms
5,280 KB
testcase_16 AC 3 ms
5,320 KB
testcase_17 AC 3 ms
5,328 KB
testcase_18 AC 3 ms
5,308 KB
testcase_19 AC 3 ms
5,284 KB
testcase_20 AC 4 ms
5,588 KB
testcase_21 AC 3 ms
5,396 KB
testcase_22 AC 3 ms
5,332 KB
testcase_23 AC 3 ms
5,332 KB
testcase_24 AC 3 ms
5,332 KB
testcase_25 AC 3 ms
5,460 KB
testcase_26 AC 3 ms
5,316 KB
testcase_27 AC 3 ms
5,300 KB
testcase_28 AC 3 ms
5,312 KB
testcase_29 AC 3 ms
5,276 KB
testcase_30 AC 3 ms
5,320 KB
testcase_31 AC 3 ms
5,276 KB
testcase_32 AC 3 ms
5,328 KB
testcase_33 AC 3 ms
5,312 KB
testcase_34 AC 3 ms
5,364 KB
testcase_35 AC 3 ms
5,296 KB
testcase_36 AC 3 ms
5,272 KB
testcase_37 AC 3 ms
5,280 KB
testcase_38 AC 3 ms
5,324 KB
testcase_39 AC 3 ms
5,444 KB
testcase_40 AC 4 ms
5,396 KB
testcase_41 AC 4 ms
5,432 KB
testcase_42 AC 4 ms
5,272 KB
testcase_43 AC 4 ms
5,300 KB
testcase_44 AC 4 ms
5,556 KB
testcase_45 AC 4 ms
5,300 KB
testcase_46 AC 4 ms
5,368 KB
testcase_47 AC 4 ms
5,304 KB
testcase_48 AC 5 ms
5,392 KB
testcase_49 AC 4 ms
5,364 KB
testcase_50 AC 4 ms
5,576 KB
testcase_51 AC 4 ms
5,300 KB
testcase_52 AC 4 ms
5,380 KB
testcase_53 AC 4 ms
5,312 KB
testcase_54 AC 4 ms
5,280 KB
testcase_55 AC 4 ms
5,440 KB
testcase_56 AC 4 ms
5,428 KB
testcase_57 AC 4 ms
5,392 KB
testcase_58 AC 4 ms
5,324 KB
testcase_59 AC 4 ms
5,320 KB
testcase_60 AC 3 ms
5,376 KB
testcase_61 AC 3 ms
5,336 KB
testcase_62 AC 4 ms
5,316 KB
testcase_63 AC 3 ms
5,296 KB
testcase_64 AC 3 ms
5,272 KB
testcase_65 AC 4 ms
5,336 KB
testcase_66 AC 4 ms
5,312 KB
testcase_67 AC 4 ms
5,504 KB
testcase_68 AC 3 ms
5,548 KB
testcase_69 AC 3 ms
5,276 KB
testcase_70 AC 3 ms
5,508 KB
testcase_71 AC 3 ms
5,300 KB
testcase_72 AC 3 ms
5,368 KB
testcase_73 AC 3 ms
5,444 KB
testcase_74 AC 3 ms
5,332 KB
testcase_75 AC 3 ms
5,276 KB
testcase_76 AC 3 ms
5,268 KB
testcase_77 AC 3 ms
5,396 KB
testcase_78 AC 3 ms
5,392 KB
testcase_79 AC 3 ms
5,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000030;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

template<class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mod(ll val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
    return val;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int N; //頂点数
ll dist[500][500]; //d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF、ただしd[i][i]=0とする)

void init() {
    for(int i = 0;i < 500;i++) {
        for(int j = 0;j < 500;j++) {
            if(i == j) {
                dist[i][j] = 0;
            }
            else {
                dist[i][j] = INF;
            }
        }
    }
}

void WarshallFloyd() {
	for(int k = 0;k < N;k++) {
		for(int i = 0;i < N;i++) {
			for(int j = 0;j < N;j++) {
                if(dist[i][k] != INF && dist[k][j] != INF) {
                    chmin(dist[i][j],dist[i][k] + dist[k][j]);
                }
			}
		}
	}
}

int main() {
    cin >> N;
    int M;
    cin >> M;
    init();
    for(int i = 0;i < M;i++) {
        int s,t;
        ll d;
        cin >> s >> t >> d;
        s--;
        t--;
        dist[s][t] = d;
    }
    WarshallFloyd();
    for(int i = 0;i < N;i++) {
        ll ret = 0;
        for(int j = 0;j < N;j++) {
            if(dist[i][j] != INF) ret += dist[i][j];
        }
        cout << ret << endl;
    }
}
0