Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define nax 100003
- using namespace std;
- vector<int> a[nax];
- int n, s, rad;
- void Citire()
- {
- int x;
- cin >> n;
- for(int i = 1; i <= n; ++i)
- {
- cin >> x;
- if(!x)
- rad = i;
- else
- a[x].push_back(i);
- }
- }
- void DFS(int node)
- {
- ++s;
- for(int& it : a[node])
- DFS(it);
- }
- int main()
- {
- Citire();
- DFS(rad);
- cout << (s == n ? "DA" : "NU");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement