Guest User

Untitled

a guest
Jan 22nd, 2017
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define vl vector<ll>
  5.  
  6. #ifndef ONLINE_JUDGE
  7. # define dbg(x) (cerr << #x << " = " << (x) << endl)
  8. #else
  9. # define dbg(x) 0
  10. #endif
  11.  
  12. vl mp[1234567];
  13. ll vis[1234567];
  14. vl v;
  15.  
  16. inline ll dfs(ll x)
  17. {
  18. vis[x]=1;
  19. for(auto it:mp[x])
  20. {
  21. if(!vis[it])
  22. return 1+dfs(it);
  23. }
  24. return 1;
  25. }
  26.  
  27.  
  28.  
  29. int main()
  30. {
  31.  
  32. ll n;
  33. cin>>n;
  34. ll i;
  35. for(i=1; i<=n; i++)
  36. {
  37. ll val;
  38. scanf("%lld",&val);
  39. mp[i].emplace_back(val);
  40. }
  41.  
  42.  
  43. for(i=1; i<n; i++)
  44. {
  45. if(!vis[i]){
  46. ll val=dfs(i);
  47. v.emplace_back(val);
  48. }
  49. }
  50.  
  51. dbg(v.size());
  52. ll ans=0;
  53. if(v.size()!=1)
  54. ans+=v.size();
  55.  
  56. ll cnt=0;
  57. for(i=1;i<=n;i++){
  58. ll val;cin>>val;
  59. cnt^=val;
  60. }
  61. if(cnt==0)
  62. ans++;
  63. cout<<ans;
  64.  
  65. }
Add Comment
Please, Sign In to add comment