a53

Duplicat

a53
Sep 7th, 2020 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. /// https://en.wikipedia.org/wiki/Cycle_detection
  2. #include <iostream>
  3. #include <bitset>
  4. #include <vector>
  5. using namespace std;
  6. using Vi=vector <int>;
  7. using bst=bitset <470001>;
  8. int n,k,ans;
  9.  
  10. int main()
  11. {
  12. cin>>n;
  13. Vi Arr;
  14. bst Occ;
  15. Arr.resize(n+1);
  16. for(int i=0;i<=n;++i)
  17. {
  18. cin>>Arr[i];
  19. if(Occ[Arr[i]])
  20. ans=Arr[i];
  21. Occ[Arr[i]]=true;
  22. }
  23. cin>>k;
  24. cout<<Arr[k-1]<<'\n'<<ans;
  25. return 0;
  26. }
Add Comment
Please, Sign In to add comment