Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define vl vector<ll>
- #ifndef ONLINE_JUDGE
- # define dbg(x) (cerr << #x << " = " << (x) << endl)
- #else
- # define dbg(x) 0
- #endif
- vl mp[1234567];
- ll vis[1234567];
- vl v;
- inline ll dfs(ll x)
- {
- vis[x]=1;
- for(auto it:mp[x])
- {
- if(!vis[it])
- return 1+dfs(it);
- }
- return 1;
- }
- int main()
- {
- ll n;
- cin>>n;
- ll i;
- for(i=1; i<=n; i++)
- {
- ll val;
- scanf("%lld",&val);
- mp[i].emplace_back(val);
- }
- for(i=1; i<n; i++)
- {
- if(!vis[i]){
- ll val=dfs(i);
- v.emplace_back(val);
- }
- }
- dbg(v.size());
- ll ans=0;
- if(v.size()!=1)
- ans+=v.size();
- ll cnt=0;
- for(i=1;i<=n;i++){
- ll val;cin>>val;
- cnt^=val;
- }
- if(cnt==0)
- ans++;
- cout<<ans;
- }
Add Comment
Please, Sign In to add comment