Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream f("lant1.in");
- ofstream g("lant1.out");
- int t[1000],n,q,x,y,m,r,u,c[1000],p,pr,a[1000][1000],viz[1000],i,L,nr,k;
- void lant(int x)
- {
- if(t[x]!=0)
- {
- lant(t[x]);
- g<<x<<' ';
- }
- }
- int main()
- {
- f>>n>>p>>q>>r;
- while(f>>x>>y)
- {
- a[x][y]=a[y][x]=1;}
- pr=1;
- u=1;
- c[pr]=r;
- viz[r]=1;
- t[r]=0;
- while(pr<=u)
- {
- x=c[pr];
- ++pr;
- for(i=1;i<=n;++i)
- if(a[i][x]==1 && viz[i]==0)
- {
- ++u;
- c[u]=i;
- viz[i]=viz[x]+1;
- t[i]=x;
- }
- }
- g<<viz[p]+viz[q]-1<<'\n';
- k=p;
- while(k!=0)
- {
- g<<k<<' ';
- k=t[k];
- }
- lant(q);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement