Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream f(".in");
  5. ofstream g(".out");
  6. int a[3][100001],n,st[100001];
  7. void citire()
  8. {
  9. f>>n;
  10. int x,y,k=0;
  11. while(f>>x>>y)
  12. {
  13. k++;
  14. a[1][k]=y;
  15. a[2][k]=st[x];
  16. st[x]=k;
  17.  
  18. }
  19. }
  20. void afis(int x)
  21. {
  22. g<<x<<" ";
  23. int unde=st[x];
  24. while(unde!=0)
  25. {
  26. g<<a[1][unde]<<" ";
  27. unde=a[2][unde];
  28. }
  29. g<<endl;
  30. }
  31. int main()
  32. { int i;
  33. citire();
  34. for(i=1; i<=n; i++)
  35. afis(i);
  36.  
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement