Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int c,f,x,y,p;
- cin>>c>>f;
- int graph[231][231],dist[231][231];
- for(int i=0;i<c;i++)
- {
- for(int j=0;j<c;j++)
- {
- if (i==j)
- graph[i][j]=0;
- else
- graph[i][j]=INT_MAX;
- }
- }
- for(int i=1;i<=f;i++)
- {
- cin>>x>>y>>p;
- graph[x][y]=p;
- graph[y][x]=p;
- }
- for(int i=0;i<c;i++)
- {
- for(int j=0;j<c;j++)
- dist[i][j]=graph[i][j];
- }
- for (int k=0;k<c;k++)
- {
- for(int i=0;i<c;i++)
- {
- for (int j=0;j<c;j++)
- {
- if (dist[i][j] > dist[i][k] + dist[k][j])
- dist[i][j] = dist[i][k] + dist[k][j];
- }
- }
- }
- int max=0;
- for(int i=0;i<c;i++)
- {
- for(int j=0;j<c;j++)
- if (max<dist[i][j]) max=dist[i][j];
- }
- cout <<max;
- }
Add Comment
Please, Sign In to add comment