結果
問題 | No.1344 Typical Shortest Path Sum |
ユーザー | 👑 emthrm |
提出日時 | 2021-01-16 13:06:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,252 bytes |
コンパイル時間 | 2,111 ms |
コンパイル使用メモリ | 214,120 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-05-05 14:54:30 |
合計ジャッジ時間 | 3,850 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 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 | AC | 2 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | WA | - |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | WA | - |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | WA | - |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | WA | - |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | WA | - |
testcase_38 | AC | 1 ms
5,376 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | AC | 2 ms
5,376 KB |
testcase_61 | AC | 1 ms
5,376 KB |
testcase_62 | AC | 2 ms
5,376 KB |
testcase_63 | AC | 1 ms
5,376 KB |
testcase_64 | AC | 2 ms
5,376 KB |
testcase_65 | AC | 2 ms
5,376 KB |
testcase_66 | AC | 2 ms
5,376 KB |
testcase_67 | AC | 1 ms
5,376 KB |
testcase_68 | AC | 2 ms
5,376 KB |
testcase_69 | AC | 2 ms
5,376 KB |
testcase_70 | WA | - |
testcase_71 | WA | - |
testcase_72 | AC | 1 ms
5,376 KB |
testcase_73 | AC | 1 ms
5,376 KB |
testcase_74 | WA | - |
testcase_75 | WA | - |
testcase_76 | WA | - |
testcase_77 | WA | - |
testcase_78 | WA | - |
testcase_79 | WA | - |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; template <typename T> struct WarshallFloyd { std::vector<std::vector<T>> graph, dist; WarshallFloyd(const std::vector<std::vector<T>> &graph, const T TINF) : graph(graph), dist(graph), TINF(TINF) { n = graph.size(); internal.assign(n, std::vector<int>(n, -1)); for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) { if (dist[i][j] > dist[i][k] + dist[k][j]) { dist[i][j] = dist[i][k] + dist[k][j]; internal[i][j] = k; } } } void add(int src, int dst, T cost) { srcs.emplace_back(src); dsts.emplace_back(dst); costs.emplace_back(cost); } void calc() { std::set<int> vers; int sz = srcs.size(); for (int i = 0; i < sz; ++i) { int s = srcs[i], t = dsts[i]; T cost = costs[i]; if (cost < graph[s][t]) graph[s][t] = cost; if (dist[s][t] >= cost) { dist[s][t] = cost; internal[s][t] = -1; } vers.emplace(s); vers.emplace(t); } for (int v : vers) { for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) { if (dist[i][j] > dist[i][v] + dist[v][j]) { dist[i][j] = dist[i][v] + dist[v][j]; internal[i][j] = v; } } } srcs.clear(); dsts.clear(); costs.clear(); } bool has_negative_cycle() const { for (int i = 0; i < n; ++i) { if (dist[i][i] < 0) return true; } return false; } std::vector<int> build_path(int s, int t) const { std::vector<int> res; if (dist[s][t] != TINF) { build_path(s, t, res); res.emplace_back(t); } return res; } private: const T TINF; int n; std::vector<std::vector<int>> internal; std::vector<int> srcs, dsts; std::vector<T> costs; void build_path(int s, int t, std::vector<int> &path) const { int k = internal[s][t]; if (k == -1) { path.emplace_back(s); } else { build_path(s, k, path); build_path(k, t, path); } } }; int main() { int n, m; cin >> n >> m; vector g(n, vector(n, LINF)); REP(i, n) g[i][i] = 0; while (m--) { int s, t; ll d; cin >> s >> t >> d; --s; --t; chmin(g[s][t], d); } WarshallFloyd wf(g, LINF); REP(i, n) { ll ans = 0; REP(j, n) { if (wf.dist[i][j] != LINF) ans += wf.dist[i][j]; } cout << ans << '\n'; } return 0; }