Language: C++

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

vector<ll>v[100100];
bool vis[100100];
unordered_map<int,pii>m1;
int p[100100];

void dfs(int i){
	vis[i]=1;
	m1[i].FF=1;m1[p[i]].SS=1;
	for(int j=0;j<v[i].size();j++){
		if(vis[v[i][j]]==0){
			dfs(v[i][j]);
		}
	}
}

int main(){
	int n,m;cin>>n>>m;
	
	for(int i=1;i<=n;i++){
		cin>>p[i];
	}
	int a,b;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	
	int ans=0;
	
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			m1.clear();
			dfs(i);
			map<int,pii>::iterator it;
		for(it=m1.begin();it!=m1.end();it++){
			if((*it).SS.FF==1&&(*it).SS.FF==(*it).SS.SS){
				ans++;
			}
		}
		}
		
	}
	
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:60:33: error: no match for 'operator=' (operand types are 'std::map<int, std::pair<int, int> >::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::pair<int, int> >, std::_Select1st<std::pair<const int, std::pair<int, int> > >, std::less<int>, std::allocator<std::pair<const int, std::pair<int, int> > > >::iterator'} and 'std::unordered_map<int, std::pair<int, int> >::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, std::pair<int, int> >, std::allocator<std::pair<const int, std::pair<int, int> > >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'})
   60 |                 for(it=m1.begin();it!=m1.end();it++){
      |                                 ^
In file included from /usr/include/c++/14/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const int, std::pair<int, int> > >& std::_Rb_tree_iterator<std::pair<const int, std::pair<int, int> > >::operator=(const std::_Rb_tree_iterator<std::pair<const int, std::pair<int, int> > >&)'
  252 |     struct _Rb_tree_iterator
      |            ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:252:12: note:   no known conversion for argument 1 from 'std::unordered_map<int, std::pair<int, int> >::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, std::pair<int, int> >, std::allocator<std::pair<const int, std::pair<int, int> > >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} to 'const std::_Rb_tree_iterator<std::pair<const int, std::pair<int, int> > >&'
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const int, std::pair<int, int> > >& std::_Rb_tree_iterator<std::pair<const int, std::pair<int, int> > >::operator=(std::_Rb_tree_iterator<std::pair<const int, std::pair<int, int> > >&&)'
/usr/include/c++/14/bits/stl_tree.h:252:12: note:   no known conversion for argument 1 from 'std::unordered_map<int, std::pair<int, int> >::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, std::pair<int, int> >, std::allocator<std::pair<const int, std::pair<int, int> > >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} to 'std::_Rb_tree_iterator<std::pair<const int, std::pair<int, int> > >&&'
a.cc:60:37: error: no match for 'operator!=' (operand types are 'std::map<int, std::pair<int, int> >::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::pair<int, int> >, std::_Select1st<std::pair<const int, std::pair<int, int> > >, std::less<int>, std::allocator<std::pair<const int, std::pair<int, int> > > >::iterator'} and 'std::unordered_map<int, std::pair<int, int> >::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, std::pair<int, int> >, std::allocator<std::pair<const int, std::pair<int, int> > >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'})
   60 |                 for(it=m1.begin();it!=m1.end();it++){
      |                                   ~~^~~~~~~~~~
      |                                   |         |
      |                                   |         std::unordered_map<int, std::pair<int, int> >::iterator {aka std::__detail::_Insert_base<int, std::pair<const int, std::pair<int, int> >, std::allocator<std::pair<const int, std::pair<int, int> > >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator}
      |                                   std::map<int, std::pair<int, int> >::iterator {aka std::_Rb_tree<int, std::pair<const int, std::pair<int, int> >, std::_Select1st<std::pair<const int, std::pair<int, int> > >, std::less<int>, std::allocator<std::pair<const int, std::pair<int, int> > > >::iterator}
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181:
/usr/include/c++/14/bits/regex.h:1132:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1132 |     operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1132:5: note:   template argument deduction/substitution failed:
a.cc:60:46: note:   'std::map<int, std::pair<int, int> >::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::pair<int, int> >, std::_Select1st<std::pair<const int, std::pair<int, int> > >, std::less<int>, std::allocator<std::pair<const int, std::pair<int, int> > > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   60 |                 for(it=m1.begin();it!=m1.end();it++){
      |                                              ^
/usr/include/c++/14/bits/regex.h:1212:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1212 |     operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1212:5: note:   template argument deduction/substitution failed:
a.cc:60:46: note:   'std::map<int, std::pair<int, int> >::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::pair<int, int> >, std::_Select1st<std::pair<const int, std::pair<int, int> > >, std::less<int>, std::allocator<std::pair<const int, std::pair<int, int> > > >::iterator'} is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>'
   60 |                 for(it=m1.begin();it!=m1.end();it++){
      |                                              ^
/usr/include/c++/14/bits/regex.h:1305:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1305 |     operator!=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1305:5: note:   template argument deduction/substitution failed:
a.cc:60:46: note:   'std::map<int, std::pair<int, int> >::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::pair<int, int> >, std::_Select1st<std::pair<const int, std::pair<int, int> > >, std::less<int>, std::allocator<std::pair<const int, std::pair<int, int> > > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   60 |                 for(it=m1.begin();it!=m1.end();it++){
      |                                              ^
/usr/include/c++/14/bits/regex.h:1379:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)'
 1379 |     operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1379:5: note:   template argument deduction/substitution failed:
a.cc:60:46: note:   'std::unordered_map<int, std::pair<int, int> >::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, std::pair<int, int> >, std::allocator<std::pair<const int, std::pair<int, int> > >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   60 |                 for(it=m1.begin();it!=m1.end();it++){
      |                                              ^
/usr/include/c++/14/bits/regex.h:1473:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1473 |     operator!=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1473:5: note:   template argument deduction/substitution failed:
a.cc:60:46: note:   'std::map<int, std::pair<int, int> >::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::pair<int, int> >, std::_Select1st<std::pair<const int, std::pair<int, int> > >, std::less<int>, std::allocator<std::pair<const int, std::pair<int, int> > > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   60 |                 for(it=m1.begin();it!=m1.end();it++){
      |                                              ^
/usr/include/c++/14/bits/regex.h:1547:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)'
 1547 |     operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1547:5: note:   template argument deduction/substitution failed:
a.cc:60:46: note:   'std::unordered_map<int, std::pair<int, int> >::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, std::pair<int, int> >, std::allocator<std::pair<const int, std::pair<int, int> > >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} is not derive