fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int a[300][300];
  4. #define MAX 100000000
  5. int main()
  6. {
  7. int c,f,x,y,p;
  8. cin>>c>>f;
  9. for(int i=1;i<=c;i++)
  10. {
  11. for(int j=1;j<=c;j++)
  12. {
  13. a[i][j]=MAX;
  14. }
  15. }
  16. for(int i=0;i<f;i++)
  17. {
  18. cin>>x>>y>>p;
  19. a[x][y]=p;
  20. }
  21. for(int i=1;i<=c;i++)
  22. {
  23. a[i][i]=0;
  24. }
  25.  
  26. for(int k=1;k<=c;k++)
  27. {
  28. for(int i=1;i<=c;i++)
  29. {
  30. for(int j=1;j<=c;j++)
  31. {
  32. if(a[i][j]>a[i][k]+a[k][j]){
  33. //cout<<"helo"<<endl;
  34.  
  35. a[i][j]=a[i][k]+a[k][j];
  36. //cout<<a[i][j]<<endl;
  37. }
  38. }
  39. }
  40. }
  41. int max=-1;
  42. for(int i=1;i<=c;i++)
  43. {
  44. for(int j=1;j<=c;j++)
  45. {
  46. if(max<a[i][j]&&a[i][j]!=MAX)
  47. max=a[i][j];
  48. }
  49. ///cout<<endl;
  50. }
  51. cout<<max<<endl;
  52. return 0;
  53. }
Runtime error #stdin #stdout 0s 15592KB
stdin
Standard input is empty
stdout
Standard output is empty