Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 5th, 2020 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4. #define endl "\n"
  5.  
  6. #define PB push_back
  7. #define F first
  8. #define S second
  9. #define all(c) (c).begin(),(c).end()
  10. #define flash ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
  11. int a[3][100005];
  12. int find(int color,int i)
  13. {
  14. int k=i;
  15.  int parent=a[1][k];
  16. while(parent!=-1)
  17. {
  18.    
  19.     if(color==a[2][parent])
  20.     return parent;
  21.     parent=a[1][parent];
  22. }
  23. return -1;
  24.  
  25. }
  26. int main()
  27. {
  28.     //ios_base::sync_with_stdio(false);
  29.     //cin.tie(NULL);
  30.     int n,c;
  31.     cin>>n>>c;
  32.     for(int i=2;i<=n;i++)
  33.     {
  34.         int data;
  35.         cin>>data;
  36.         a[1][i]=data;
  37.     }
  38.     a[1][1]=-1;
  39.     for(int i=1;i<=n;i++)
  40.     {
  41.         cin>>a[2][i];
  42.     }
  43.     for(int i=1;i<=n;i++)
  44.     {
  45.         int color=a[2][i];
  46.         int ans=find(color,i);
  47.         cout<<ans<<" ";
  48.     }
  49.  
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top