Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. //rip zadanko
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. const long long N=1e5+10;
  5. #define ll long long
  6. #define pi pair<ll,ll>
  7. #define ft first
  8. #define sd second
  9. #define mp make_pair
  10. #define pb push_back
  11.  
  12. #define VI vector<int>
  13. #define int ll
  14. #define PI 3.14159265
  15. int n;
  16. int G[N][2];
  17. int H[N][2];
  18. int podobne(int idG, int idH)
  19. {
  20.     if(idG==0 && idH==0)
  21.         return true;
  22.     if(idG == 0 || idH == 0)
  23.         return false;
  24.     return ((podobne(G[idG][0], H[idH][0]) && podobne(G[idG][1], H[idH][1])) ||
  25.            (podobne(G[idG][1], H[idH][0]) && podobne(G[idG][0], H[idH][1])));
  26. }
  27.  
  28. #undef int
  29. int main()
  30. {
  31.     #define int ll
  32.     ios_base::sync_with_stdio(0);
  33.     cin.tie(0);
  34.     cerr.tie(0);
  35.     cin>>n;
  36.     for(int i=1;i<=n;i++)
  37.         cin>>G[i][0]>>G[i][1];
  38.     for(int i=1;i<=n;i++)
  39.         cin>>H[i][0]>>H[i][1];
  40.     if(podobne(1, 1))
  41.         cout<<"TAK\n";
  42.     else
  43.         cout<<"NIE\n";
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement