Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Parcurgerea in adancime
  4.  
  5. *******************************************************************************/
  6.  
  7. #include <fstream>
  8. using namespace std;
  9.  
  10. ifstream f("date.in");
  11. ofstream g("date.out");
  12.  
  13. int a[20][20],x,y,m,n,i,v[20];
  14.  
  15. void df(int x)
  16. {
  17. g<<x<<" ";
  18. v[x]=1;
  19. int i;
  20. for(i=1;i<=n;i++)
  21. if(a[i][x]==1 && v[i]==0) df(i);
  22. }
  23.  
  24. int main()
  25. {
  26. f>>n>>m;
  27. for(i=1;i<=m;i++)
  28. {
  29. f>>x>>y;
  30. a[x][y]=a[y][x]=1;
  31. }
  32. f>>x;
  33. df(x);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement