SHARE
TWEET

Untitled

a guest Jan 24th, 2020 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("vot1.in");
  5. ofstream fout("vot1.out");
  6.  
  7. int n, sol, f[1005], d[1005];
  8. bitset<1005> viz;
  9. vector<int> v;
  10.  
  11. int main()
  12. {
  13.     fin >> n;
  14.     for(int i=1; i<=n; i++)
  15.     {
  16.         fin >> f[i];
  17.         d[f[i]]++;
  18.     }
  19.     for(int j=1; j<=n; j++)
  20.     {
  21.         int i=j;
  22.         while(!d[i])
  23.         {
  24.             viz[i]=1;
  25.             sol++;
  26.             d[f[i]]--;
  27.             i=f[i];
  28.         }
  29.     }
  30.     fout << n-sol << "\n";
  31.     for(int i=1; i<=n; i++)
  32.         if(!viz[i])
  33.             fout << i << " ";
  34.     return 0;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top