Advertisement
UltraTDK

Untitled

Oct 15th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int N, v[1001], grupe = 0;
  7. cin >> N;
  8. for (int i = 1; i <= N; i++)
  9. cin >> v[i];
  10. for (int i = 1; i <= N; i++)
  11. for (int j = 1; j <= N; j++)
  12. {
  13. if (v[i] == j && v[j] == i && v[i] > -1 && v[j] > -1)
  14. {
  15. grupe++;
  16. v[i] = -1;
  17. v[j] = -1;
  18. break;
  19. }
  20. }
  21. cout << grupe;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement