Advertisement
STANAANDREY

diam graf

Mar 8th, 2021
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. ///**********************
  4. const int NMAX = 103;
  5. int n, c[NMAX][NMAX], ans, m;
  6.  
  7. void read() {
  8.     cin >> n >> m;
  9.     for (int i = 0; i < m; i++) {
  10.         int x, y, cost;
  11.         cin >> x >> y >> cost;
  12.         c[x][y] = cost;
  13.     }
  14. }
  15.  
  16. void solve() {
  17.     for (int k = 1; k <= n; k++)
  18.         for (int i = 1; i <= n; i++)
  19.             for (int j = 1; j <= n; j++)
  20.                 if (c[i][k] && c[k][j] && i != j && (c[i][j] > c[i][k] + c[k][j] || !c[i][j])) {
  21.                     c[i][j] = c[i][k] + c[k][j];
  22.                     ans = max(ans, c[i][j]);
  23.                 }
  24. }
  25.  
  26. int main() {
  27.     read();
  28.     solve();
  29.     cout << ans << endl;
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement