Advertisement
a53

CountSub

a53
Dec 28th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("countsub.in");
  4. ofstream fout("countsub.out");
  5. int n,x, s[1001], d[1001];
  6. int count(int k)
  7. {
  8. if(k==0) return 0;
  9. else return 1+count(s[k])+count(d[k]);
  10. }
  11.  
  12. int main()
  13. {
  14. fin>>n;
  15. for(int i=1;i<=n;i++)
  16. fin>>x>>s[i]>>d[i];
  17. int k,y;
  18. fin>>k;
  19. for(int i=1;i<=k;i++)
  20. {
  21. fin>>y;
  22. fout<<count(y)<<'\n';
  23. }
  24. fin.close();
  25. fout.close();
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement