#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/graph.hpp" #include template 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& e) const { return cost < e.cost; } bool operator>(const Edge& e) const { return cost > e.cost; } }; template struct Graph : public std::vector>> { using std::vector>>::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 #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; }