Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- #include<queue>
- using namespace std ;
- ifstream fin("prog.in");
- ofstream fout("prog.out");
- queue <int> q;
- int a[100][100], n , x , y;
- void citire()
- {
- int i , j;
- fin>>n>>x>>y;
- while(fin>>i>>j)
- a[i][j]=a[j][i]=1;
- fin.close();
- }
- void BF(int nd,int sel[], int t[])
- {
- int i , j;
- sel[nd]=1;
- q.push(nd);
- while(!q.empty())
- {
- i=q.front();
- for( j =1;j<=n;j++)
- if(a[i][j]==1 && sel[j]==0)
- {
- sel[j]=1;
- t[j]=i;
- q.push(j);
- }
- q.pop();
- }
- }
- void drum(int final, int t[])
- {
- if (t[final]!=0)
- {
- drum(t[final],t);
- fout<<final<<' ';
- }
- }
- int main()
- {
- citire();
- int t[100];
- int sel[100];
- for(int i=1;i<=n;i++)
- sel[i]=t[i]=0;
- BF(x,sel,t);
- for(int i=1;i<=7;i++)
- fout<<t[i]<<' ';
- if(t[y]!=0)
- drum(y,t);
- else
- fout<<"Nu exista drum"<<endl;
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement