Language: C++


#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include<map>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_2 100000
#define d9_7 1000000007
struct edge{
  struct treev* to;
  ll length;
  int type;//0が道路、1が鉄道
};
struct treev{
  int num;
  vector<edge> nexts;
};
//UNION FIND
//構造体
struct uunion{
  int num;
  int size;
};
uunion par1[200000];//親の番号
vector<bool> record(200000,false);
//n要素で初期化
void init1(int n){
  rep(i,n){
    par1[i].num=i;
    par1[i].size=1;
  }
}
//木の根を求める
int root1(int x){
  if(par1[x].num==x){
    return x;
  }else{
    return par1[x].num=root1(par1[x].num);//経路圧縮
  }
}
//属する集合の要素数を求める
int size1(int x){
  return par1[root1(x)].size;
}
//x,yが同じ集合に属するか否か
bool same1(int x,int y){
  return (root1(x)==root1(y));
}
//x,yの属する集合を併合
void unite1(int x,int y){
  x=root1(x);
  y=root1(y);
  if(x==y)return;
  par1[y].size += par1[x].size;
  par1[x].num = y;
}


uunion par2[200000];//親の番号
//n要素で初期化
void init2(int n){
  rep(i,n){
    par2[i].num=i;
    par2[i].size=1;
  }
}
//木の根を求める
int root2(int x){
  if(par2[x].num==x){
    return x;
  }else{
    return par2[x].num=root2(par2[x].num);//経路圧縮
  }
}
//属する集合の要素数を求める
int size2(int x){
  return par2[root2(x)].size;
}
//x,yが同じ集合に属するか否か
bool same2(int x,int y){
  return (root2(x)==root2(y));
}
//x,yの属する集合を併合
void unite2(int x,int y){
  x=root2(x);
  y=root2(y);
  if(x==y)return;
  par2[y].size += par2[x].size;
  par2[x].num = y;
}
uunion par3[200000];//親の番号
//n要素で初期化
void init3(int n){
  rep(i,n){
    par3[i].num=i;
    par3[i].size=1;
  }
  return;
}
//木の根を求める
int root3(int x){
  if(par3[x].num==x){
    return x;
  }else{
    return par3[x].num=root3(par3[x].num);//経路圧縮
  }
}
//属する集合の要素数を求める
int size3(int x){
  return par3[root3(x)].size;
}
//x,yが同じ集合に属するか否か
bool same3(int x,int y){
  return (root3(x)==root3(y));
}
//x,yの属する集合を併合
void unite3(int x,int y){
  x=root3(x);
  y=root3(y);
  if(x==y)return;
  par3[y].size += par3[x].size;
  par3[x].num = y;
}
//木構造グラフ

struct input{
  int u;
  int v;
};
bool cmp(const input &a, const input &b)//ソート用
{
  if(a.u!=b.u){
    return a.u<b.u;
  }else{
    return a.v<b.v;

  }
}
vector<treev*> vs;
treev* createtreenode(int num){
  treev* newt=new treev;
  if(newt==NULL){
    cout << "memory error" << endl;
    while(1){
      num=1;//メモリエラー対策
    }
  }
  newt->num=num;
  newt->nexts={};
  //cout << "fff" << endl;
  return newt;
}
void insertree(ll len,int Va,int Vb,int type){//結ぶ頂点を
  vs[Va]->nexts.push_back({vs[Vb],len,type});
  vs[Vb]->nexts.push_back({vs[Va],len,type});
  return;
}
void search1(int root,ll depth,int pre){
  record[root]=true;
  //cout << "eee" << endl;
  //ここにやりたい処理を書く
  if(pre!=-1){
    unite1(root,pre);
  }
  for(auto i:vs[root]->nexts){
    if(pre==i.to->num || i.type==1||record[i.to->num]==true){
      continue;
    }
    search1(i.to->num,depth+i.length,root);
  }
  return;
}
void search2(int root,ll depth,int pre){
  record[root]=true;
  //cout << "eee" << endl;
  //ここにやりたい処理を書く
  if(pre!=-1){
    unite2(root,pre);
  }
  for(auto i:vs[root]->nexts){
    if(pre==i.to->num || i.type==0||record[i.to->num]==true){
      continue;
    }
    search2(i.to->num,depth+i.length,root);
  }
  return;
}
void search3(int root,ll depth,int pre){
  record[root]=true;
  if(pre!=-1){
    if(same1(root,pre)&&same2(root,pre)){
      unite3(root,pre);
    }
  }

  //ここにやりたい処理を書く
  for(auto i:vs[root]->nexts){
    if(pre==i.to->num||record[i.to->num]==true){
      continue;
    }
    search3(i.to->num,depth+i.length,root);
  }
  return;
}

int main(void){
  int n,k,l,p,q,r,s;
  cin >> n>>k>>l;
  rep(i,n){
    vs.push_back(createtreenode(i));
  }
  rep(i,k){
    cin>>p>>q;
    p--;q--;
    insertree(1,p,q,0);
  }
  rep(i,l){
    cin>>r>>s;
    r--;s--;
    insertree(1,r,s,1);
  }
  init1(n);
  rep(i,n){
    if(record[i]==false){
      search1(i,0,-1);
    }
  }
  init2(n);
  rep(i,n){
    record[i]=false;
  }
  rep(i,n){
    if(record[i]==false){
      search2(i,0,-1);
      //cout<<i<<endl;
    }
  }
  /*rep(i,n){
    record[i]=false;
  }
  init3(n);
  rep(i,n){
    if(record[i]==false){
      search3(i,0,-1);
    }
  }*/
  /*rep(i,n){
    cout<<par1[i].num<<" ";
  }
  cout<<endl;
  rep(i,n){
    cout<<par2[i].num<<" ";
  }
  cout<<endl;*/
  multimap<pair<int,int>,int> m;
  rep(i,n){
    m.insert((root1(i),root2(i)),1);
  }
  rep(i,n){
    auto c=m.count((root1(i),root2(i)));
    cout<<c<<" ";
  }
  cout<<endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:273:19: error: no matching function for call to 'std::multimap<std::pair<int, int>, int>::count(int)'
  273 |     auto c=m.count((root1(i),root2(i)));
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/map:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_multimap.h:897:9: note: candidate: 'template<class _Kt> decltype (((const std::multimap<_Key, _Tp, _Compare, _Alloc>*)this)->std::multimap<_Key, _Tp, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::multimap<_Key, _Tp, _Compare, _Alloc>::count(const _Kt&) const [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
  897 |         count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
      |         ^~~~~
/usr/include/c++/14/bits/stl_multimap.h:897:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_multimap.h: In substitution of 'template<class _Kt> decltype (((const std::multimap<std::pair<int, int>, int>*)this)->std::multimap<std::pair<int, int>, int>::_M_t.std::_Rb_tree<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::_Select1st<std::pair<const std::pair<int, int>, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<const std::pair<int, int>, int> > >::_M_count_tr<_Kt, _Req>(__x)) std::multimap<std::pair<int, int>, int>::count(const _Kt&) const [with _Kt = int]':
a.cc:273:19:   required from here
  273 |     auto c=m.count((root1(i),root2(i)));
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_multimap.h:897:65: error: no matching function for call to 'std::_Rb_tree<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::_Select1st<std::pair<const std::pair<int, int>, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<const std::pair<int, int>, int> > >::_M_count_tr(const int&) const'
  897 |         count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
      |                                                 ~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/map:62:
/usr/include/c++/14/bits/stl_tree.h:1311:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_count_tr(const _Kt&) const [with _Req = _Kt; _Key = std::pair<int, int>; _Val = std::pair<const std::pair<int, int>, int>; _KeyOfValue = std::_Select1st<std::pair<const std::pair<int, int>, int> >; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
 1311 |         _M_count_tr(const _Kt& __k) const
      |         ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1311:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/stl_function.h: In substitution of 'template<class _Func, class _SfinaeType> using std::__has_is_transparent_t = typename std::__has_is_transparent<_Func, _SfinaeType>::type [with _Func = std::less<std::pair<int, int> >; _SfinaeType = int]':
/usr/include/c++/14/bits/stl_tree.h:1309:9:   required by substitution of 'template<class _Kt> decltype (((const std::multimap<std::pair<int, int>, int>*)this)->std::multimap<std::pair<int, int>, int>::_M_t.std::_Rb_tree<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::_Select1st<std::pair<const std::pair<int, int>, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<const std::pair<int, int>, int> > >::_M_count_tr<_Kt, _Req>(__x)) std::multimap<std::pair<int, int>, int>::count(const _Kt&) const [with _Kt = int]'
 1309 |                typename _Req = __has_is_transparent_t<_Compare, _Kt>>
      |                ^~~~~~~~
a.cc:273:19:   required from here
  273 |     auto c=m.count((root1(i),root2(i)));
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:1427:11: error: no type named 'type' in 'struct std::__has_is_transparent<std::less<std::pair<int, int> >, int, void>'
 1427 |     using __has_is_transparent_t
      |           ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_multimap.h:891:7: note: candidate: 'std::multimap<_Key, _Tp, _Compare, _Alloc>::size_type std::multimap<_Key, _Tp, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; size_type = long unsigned int; key_type = std::pair<int, int>]'
  891 |       count(const key_type& __x) const
      |       ^~~~~
/usr/include/c++/14/bits/stl_multimap.h:891:29: note:   no known conversion for argument 1 from 'int' to 'const std::multimap<std::pair<int, int>, int>::key_type&' {aka 'const std::pair<int, int>&'}
  891 |       count(const key_type& __x) const
      |             ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_multimap.h: In instantiation of 'void std::multimap<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]':
a.cc:270:13:   required from here
  270 |     m.insert((root1(i),root2(i)),1);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_multimap.h:620:37: error: no matching function for call to 'std::_Rb_tree<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::_Select1st<std::pair<const std::pair<int, int>, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<const std::pair<int, int>, int> > >::_M_insert_range_equal(int&, int&)'
  620 |         { _M_t._M_insert_range_equal(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1113:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<((bool)std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value)> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_equal(_InputIterator, _InputIterator) [with _Key = std::pair<int, int>; _Val = std::pair<const std::pair<int, int>, int>; _KeyOfValue = std::_Select1st<std::pair<const std::pair<int, int>, int> >; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
 1113 |         _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1113:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<((bool)std::is_same<std::pair<const std::pair<int, int>, int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value), void> std::_Rb_tree<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::_Select1st<std::pair<const std::pair<int, int>, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<const std::pair<int, int>, int> > >::_M_insert_range_equal(_InputIterator, _InputIterator) [with _InputIterator = int]':
/usr/include/c++/14/bits/stl_multimap.h:620:30:   required from 'void std::multimap<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
  620 |         { _M_t._M_insert_range_equal(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:270:13:   required from here
  270 |     m.insert((root1(i),root2(i)),1);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1095:58: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
 1095 |         __enable_if_t<__same_value_type<_InputIterator>::value>
      |                                                          ^~~~~
/usr/include/c++/14/bits/stl_multimap.h: In instantiation of 'void std::multimap<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]':
a.cc:270:13:   required from here
  270 |     m.insert((root1(i),root2(i)),1);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1122:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<((bool)(! std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value))> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_equal(_InputIterator, _InputIterator) [with _Key = std::pair<int, int>; _Val = std::pair<const std::pair<int, int>, int>; _KeyOfValue = std::_Select1st<std::pair<const std::pair<int, int>, int> >; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
 1122 |         _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1122:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<((bool)(! std::is_same<std::pair<const std::pair<int, int>, int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value)), void> std::_Rb_tree<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::_Select1st<std::pair<const std::pair<int, int>, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<const std::pair<int, int>, int> > >::_M_insert_range_equal(_InputIterator, _InputIterator) [