結果

問題 No.1344 Typical Shortest Path Sum
ユーザー maguromaguro
提出日時 2021-01-13 21:51:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,133 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 203,088 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-04 22:05:06
合計ジャッジ時間 3,521 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,948 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 3 ms
6,944 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 3 ms
6,940 KB
testcase_33 AC 3 ms
6,940 KB
testcase_34 AC 3 ms
6,940 KB
testcase_35 AC 3 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 4 ms
6,944 KB
testcase_41 AC 4 ms
6,940 KB
testcase_42 AC 4 ms
6,940 KB
testcase_43 AC 4 ms
6,944 KB
testcase_44 AC 3 ms
6,940 KB
testcase_45 AC 3 ms
6,944 KB
testcase_46 AC 3 ms
6,944 KB
testcase_47 AC 4 ms
6,944 KB
testcase_48 AC 4 ms
6,940 KB
testcase_49 AC 4 ms
6,940 KB
testcase_50 AC 3 ms
6,944 KB
testcase_51 AC 3 ms
6,944 KB
testcase_52 AC 3 ms
6,940 KB
testcase_53 AC 3 ms
6,940 KB
testcase_54 AC 3 ms
6,940 KB
testcase_55 AC 3 ms
6,944 KB
testcase_56 AC 3 ms
6,940 KB
testcase_57 AC 3 ms
6,940 KB
testcase_58 AC 4 ms
6,940 KB
testcase_59 AC 3 ms
6,944 KB
testcase_60 AC 3 ms
6,940 KB
testcase_61 AC 3 ms
6,940 KB
testcase_62 AC 3 ms
6,940 KB
testcase_63 AC 3 ms
6,940 KB
testcase_64 AC 3 ms
6,940 KB
testcase_65 AC 4 ms
6,940 KB
testcase_66 AC 4 ms
6,944 KB
testcase_67 AC 4 ms
6,944 KB
testcase_68 AC 3 ms
6,940 KB
testcase_69 AC 3 ms
6,944 KB
testcase_70 AC 2 ms
6,944 KB
testcase_71 AC 3 ms
6,940 KB
testcase_72 AC 3 ms
6,944 KB
testcase_73 AC 3 ms
6,944 KB
testcase_74 AC 2 ms
6,940 KB
testcase_75 AC 3 ms
6,940 KB
testcase_76 AC 2 ms
6,944 KB
testcase_77 AC 3 ms
6,940 KB
testcase_78 AC 3 ms
6,940 KB
testcase_79 AC 3 ms
6,944 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<int,int> 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,M; //頂点数
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 >> M;
    assert(1 <= N && N <= 100 && 1 <= M && M <= 9990);
    init();
    for(int i = 0;i < M;i++) {
        int s,t;
        ll d;
        cin >> s >> t >> d;
        assert(1 <= s && s <= N && 1 <= t && t <= N && s != t);
        s--;
        t--;
        chmin(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