結果

問題 No.1344 Typical Shortest Path Sum
ユーザー Mister
提出日時 2021-01-23 15:01:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,688 bytes
コンパイル時間 826 ms
コンパイル使用メモリ 75,516 KB
最終ジャッジ日時 2025-01-18 07:29:33
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 77
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/graph.hpp"

#include <vector>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;

    Edge() = default;
    Edge(int src, int dst, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return cost > e.cost; }
};

template <class Cost = int>
struct Graph : public std::vector<std::vector<Edge<Cost>>> {
    using std::vector<std::vector<Edge<Cost>>>::vector;

    void span(bool direct, int src, int dst, Cost cost = 1) {
        (*this)[src].emplace_back(src, dst, cost);
        if (!direct) (*this)[dst].emplace_back(dst, src, cost);
    }
};
#line 2 "main.cpp"
#include <iostream>
#line 4 "main.cpp"

using namespace std;
using lint = long long;
constexpr lint INF = 1LL << 60;

void solve() {
    int n, m;
    cin >> n >> m;

    auto dss = vector(n, vector(n, INF));
    for (int v = 0; v < n; ++v) dss[v][v] = 0;
    while (m--) {
        int u, v;
        lint d;
        cin >> u >> v >> d;
        --u, --v;
        dss[u][v] = min(dss[u][v], d);
    }

    for (int v = 0; v < n; ++v) {
        for (int u = 0; u < n; ++u) {
            for (int w = 0; w < n; ++w) {
                dss[u][w] = min(dss[u][w], dss[u][v] + dss[v][w]);
            }
        }
    }

    for (int v = 0; v < n; ++v) {
        lint s = 0;
        for (int u = 0; u < n; ++u) {
            if (dss[v][u] < INF / 2) s += dss[v][u];
        }
        cout << s << "\n";
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0