Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream cin("dfs.in");
  6. ofstream cout("dfs.out");
  7.  
  8. int n,m,p,c=0,viz[10001],a[102][102],k=0;
  9.  
  10. void DF(int nod)
  11. {
  12. cout << nod << " ";
  13. viz[nod]=1;
  14. for(int i=1;i<=n;i++)
  15. {
  16. if(a[nod][i]==1 && viz[i]==0)
  17. {
  18. DF(i);
  19. }
  20. }
  21. }
  22.  
  23. void Citire()
  24. {
  25. int x,y;
  26. int contor=1;
  27. for(int i=1;i<=m;i++)
  28. {
  29. cin >> x >> y;
  30. a[x][y]=a[y][x]=1;
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. cin >> n >> m >> p;
  37. Citire();
  38.  
  39. DF(p);
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement