Advertisement
bluetastymelon

#650

Feb 18th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f("knivel.in");
  7. ofstream g("knivel.out");
  8.  
  9. int a[101][101],t[101],viz[101],poz,n,cont=1,k;
  10.  
  11. void DFS(int start)
  12. {
  13. viz[start]=cont;
  14. for(int i=1;i<=n;i++)
  15. if(a[start][i] and viz[i]==0)
  16. {
  17. cont++;
  18. DFS(i);
  19. cont--;
  20. }
  21. }
  22.  
  23. void citire()
  24. {
  25. int i;
  26. f>>n>>k;
  27. for(i=1;i<=n;i++)
  28. {
  29. f>>t[i];
  30. if(t[i]==0)
  31. poz=i;
  32. a[i][t[i]]=a[t[i]][i]=1;
  33. }
  34. }
  35.  
  36. int main()
  37. {
  38. int i;
  39. citire();
  40. DFS(poz);
  41. for(i=1;i<=n;i++)
  42. if(viz[i]==k)
  43. g<<i<<" ";
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement