Advertisement
rembocoder

Untitled

Mar 16th, 2023
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int int64_t
  6.  
  7. const int mod = 998244353;
  8. const int max_n = 500;
  9. int d[max_n][max_n];
  10.  
  11. int32_t main() {
  12.     ios_base::sync_with_stdio(false);
  13.     cin.tie(0); cout.tie(0);
  14.     int n, m;
  15.     cin >> n >> m;
  16.     for (int i = 0; i < n; i++) {
  17.         for (int j = 0; j < n; j++) {
  18.             d[i][j] = 2e18;
  19.         }
  20.     }
  21.     for (int i = 0; i < m; i++) {
  22.         int a, b, c;
  23.         cin >> a >> b >> c;
  24.         d[a][b] = min(d[a][b], c);
  25.         d[b][a] = min(d[b][a], c);
  26.     }
  27.     // dp(i)[a][b] = shortest path from a to b that uses only vertices [0..i) and a, b
  28.     for (int i = 0; i < n; i++) {
  29.         for (int a = 0; a < n; a++) {
  30.             for (int b = 0; b < n; b++) {
  31.                 d[a][b] = min(d[a][b], d[a][i] + d[i][b]);
  32.             }
  33.         }
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement