Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("warshall.in");
- ofstream g("warshall.out");
- int a[100][100],n,m;
- void construire ()
- {
- int x,y;
- f>>n>>m;
- for(int i=1; i<=m; i++)
- {
- f>>x>>y;
- a[x][y]=1;
- }
- }
- void afisare()
- {
- int i,j;
- for(i=1; i<=n; i++)
- {
- for(j=1; j<=n; j++)
- g<<a[i][j]<<" ";
- g<<" \n";
- }
- g<<"\n";
- }
- void warshall()
- {
- int i,j,k;
- for(k=1; k<=n; k++)
- {
- for(i=1; i<=n; i++)
- {
- for(j=1; j<=n; j++)
- if(a[i][j]==0 && i!=k && j!=k)
- a[i][j]=a[i][k]*a[k][j];
- }
- }
- }
- int main()
- {
- construire();
- afisare();
- warshall();
- g<<"DUPA : \n";
- afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement