Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- long long path[1000][1000];
- int main()
- {
- int node,edge,i,j,k;
- cin>>node>>edge;
- memset(path,1,sizeof(path));
- for(i=0;i<edge;i++)
- {
- char a,b;
- int cost;
- cin>>a>>b;
- cin>>cost;
- path[a-'A'][b-'A']=cost;
- path[b-'A'][a-'A']=cost;
- path[a-'A'][a-'A']=0;
- path[b-'A'][b-'A']=0;
- }
- for(i=0;i<node;i++)
- {
- for(j=0;j<node;j++)
- {
- for(k=0;k<node;k++)
- {
- if(path[j][k]>path[j][i]+path[i][k])
- path[j][k]=path[j][i]+path[i][k];
- }
- }
- }
- for(i=0;i<node;i++)
- {
- printf("%c-->[ ",i+'A');
- for(j=0;j<node;j++)
- {
- printf("(%c)%d ",j+'A',path[i][j]);
- }
- printf("]\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement