Advertisement
jeff69

Untitled

Oct 20th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5. typedef long double ld;
  6. const int MX=1e5+5;
  7. int pa[MX][64];
  8. int st[MX],n,k,m;
  9. int main()
  10. {
  11. cin>>n>>k>>m;
  12. for(int i=0;i<n;i++)
  13. scanf("%d",st+i);
  14. for(int i=0;i<k;i++)
  15. {
  16. int x;
  17. scanf("%d",&x);
  18. pa[i+1][0]=x;
  19. }
  20. m--;
  21. for(int j=1;j<=k;j++){
  22. for(int i=1;i<=31;i++)
  23. {
  24. pa[j][i]=pa[pa[j][i-1]][i-1];
  25. //if(j==5)cout<<pa[j][i]<<endl;
  26. }
  27. }
  28. for(int i=0;i<n;i++)
  29. {
  30. for(int j=0;j<32;j++)
  31. {
  32. if((1<<j)&m){
  33. if(!pa[st[i]][j])break;
  34. st[i]=pa[st[i]][j];
  35.  
  36. }
  37. }
  38. }
  39. for(int i=0;i<n;i++)
  40. {
  41. printf("%d ",st[i]);
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement