Advertisement
a53

tata

a53
Dec 16th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #define Nmax 100001
  3. using namespace std;
  4. int n,t[Nmax],v[Nmax];
  5.  
  6. void dfs(int k)
  7. {
  8. v[k]=1;
  9. for(int i=1;i<=n;++i)
  10. if(t[i]==k)
  11. dfs(i);
  12. }
  13.  
  14. int main()
  15. {
  16. cin>>n;
  17. int rad=0;
  18. for(int i=1;i<=n;++i)
  19. {
  20. cin>>t[i];
  21. if(t[i]==0)
  22. rad=i;
  23. }
  24. if(rad==0)
  25. cout<<"NU";
  26. else
  27. {
  28. dfs(rad);
  29. for(int i=1;i<=n;++i)
  30. if(v[i]==0)
  31. {
  32. cout<<"NU";
  33. return 0;
  34. }
  35. cout<<"DA";
  36. }
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement