Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int int64_t
- const int mod = 998244353;
- const int max_n = 500;
- int d[max_n][max_n];
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- int n, m;
- cin >> n >> m;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- d[i][j] = 2e18;
- }
- }
- for (int i = 0; i < m; i++) {
- int a, b, c;
- cin >> a >> b >> c;
- d[a][b] = min(d[a][b], c);
- d[b][a] = min(d[b][a], c);
- }
- // dp(i)[a][b] = shortest path from a to b that uses only vertices [0..i) and a, b
- for (int i = 0; i < n; i++) {
- for (int a = 0; a < n; a++) {
- for (int b = 0; b < n; b++) {
- d[a][b] = min(d[a][b], d[a][i] + d[i][b]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement