Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<conio.h>
- struct nod{int info;nod*leg};
- nod *l[50],*p;
- int n,a[50][50]={0},x,y;
- const int inf=10000;
- void citire()
- {
- ifstream f("graf.txt");
- int i,j,c;
- f>>n;
- for(i=1;i<=n;i++)
- for(j=1;j<=n;j++)if(i!=j)a[i][j]=inf;
- while(f>>i>>j>>c)
- {
- a[i][j]=a[j][i]=c;
- }
- f.close();
- }
- void afisare()
- {
- for(int i=1;i<=n;i++)
- {
- cout<<endl;
- for(int j=1;j<=n;j++)cout<<a[i][j]<<" ";
- }
- }
- void drum()
- {
- for(int k=1;k<=n;k++)
- for(int i=1;i<=n;i++)
- for(int j=1;j<=n;j++)
- if(a[i][j]>a[i][k]+a[k][j])a[i][j]=a[i][k]+a[k][j];
- }
- void subprogram(int x,int y)
- {
- bool g=false;
- int k=1;
- while(k<=n&&!g)
- {
- if(k!=x&&k!=y)
- if(a[x][y]==a[x][k]+a[k][y])
- {
- g=true;
- subprogram(x,k);
- subprogram(k,y);
- }
- }
- void scriere(int x,int y)
- {
- drum();
- if(a[x][y]<inf)
- {
- cout<<"Drumul de la"<<" "<<x<<" "<<"la"<<" "<<y<<" "<<este<<" "<<a[x][y];
- cout<<"Nodul de plecare este "<<x;
- drum(x,y);
- }
- else cout<<"Nu este drum ";
- }
- int main()
- {
- citire();afisare();drum();
- cout<<"x=";cin>>x;cout<<endl;
- cout<<"y= ";cin>>y;cout<<endl;
- subprogram(x,y);
- scriere(x,y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement