Advertisement
jakaria_hossain

Floyed Warshal

Oct 23rd, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long path[1000][1000];
  4. int main()
  5. {
  6. int node,edge,i,j,k;
  7. cin>>node>>edge;
  8. memset(path,1,sizeof(path));
  9. for(i=0;i<edge;i++)
  10. {
  11. char a,b;
  12. int cost;
  13.  
  14. cin>>a>>b;
  15. cin>>cost;
  16. path[a-'A'][b-'A']=cost;
  17. path[b-'A'][a-'A']=cost;
  18.  
  19. path[a-'A'][a-'A']=0;
  20. path[b-'A'][b-'A']=0;
  21.  
  22. }
  23. for(i=0;i<node;i++)
  24. {
  25. for(j=0;j<node;j++)
  26. {
  27. for(k=0;k<node;k++)
  28. {
  29. if(path[j][k]>path[j][i]+path[i][k])
  30. path[j][k]=path[j][i]+path[i][k];
  31. }
  32. }
  33. }
  34. for(i=0;i<node;i++)
  35. {
  36. printf("%c-->[ ",i+'A');
  37. for(j=0;j<node;j++)
  38. {
  39. printf("(%c)%d ",j+'A',path[i][j]);
  40. }
  41. printf("]\n");
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement