SHARE
TWEET

Untitled

a guest Mar 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. int a[100][100],m,n;
  5. int main()
  6. {
  7.     ifstream f("graf.in");
  8.     int x,y,c,k,i,j;
  9.     f>>n>>m;
  10.     for(i=1;i<=m;i++)
  11.     {
  12.         f>>x>>y>>c;
  13.         a[x][y]=c;
  14.     }
  15.     for(i=1;i<=m;i++)
  16.         for(j=1;j<=n;j++)
  17.             if(a[i][j]==0&&i!=j)
  18.                 a[i][j]=1000000000;
  19.     for(k=1;k<=n;k++)
  20.         for(i=1;i<=n;i++)
  21.             if(i!=k)
  22.                 for(j=1;j<=n;j++)
  23.                     if(j!=k)
  24.                         if(a[i][j]>a[i][k]+a[k][j])
  25.                             a[i][j]=a[i][k]+a[k][j];
  26.     for(i=1;i<=n;i++)
  27.         for(j=1;j<=n;j++)
  28.             if(i!=j)
  29.                 if(a[i][j]==1000000000)
  30.                     cout<<"nu exista drum intre "<<i<<" si "<<j<<"\n";
  31.                 else
  32.                     cout<<"drumul minim intre "<<i<<" si "<<j<<" este "<<a[i][j]<<"\n";
  33.     return 0;
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top