Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// https://en.wikipedia.org/wiki/Cycle_detection
- #include <iostream>
- #include <bitset>
- #include <vector>
- using namespace std;
- using Vi=vector <int>;
- using bst=bitset <470001>;
- int n,k,ans;
- int main()
- {
- cin>>n;
- Vi Arr;
- bst Occ;
- Arr.resize(n+1);
- for(int i=0;i<=n;++i)
- {
- cin>>Arr[i];
- if(Occ[Arr[i]])
- ans=Arr[i];
- Occ[Arr[i]]=true;
- }
- cin>>k;
- cout<<Arr[k-1]<<'\n'<<ans;
- return 0;
- }
Add Comment
Please, Sign In to add comment