Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <set>
- using namespace std;
- const int maxn=500000;
- int main() {
- int n;
- cin >> n;
- int nodes_as_trees = 0;
- set<int> st;
- for(int i = 1; i <= n; i++) {
- int x;
- cin >> x;
- if(x == i) {
- nodes_as_trees++;
- }
- else {
- st.insert(x);
- }
- }
- cout << (int) st.size() / 2 + nodes_as_trees << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement