Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 1000000000000000000
#define MOD 1000000007
#define MAX 3000000
using Graph=vector<vector<int>>;

map<pair<ll,ll>,ll> m;

bool dfs(Graph &G,ll v,ll p,ll g,ll &ans){
  for(auto nv:G.at(v)){
    if(nv==p){
      continue;
    }
    if(nv==g){
      ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      ans=x;
      return true;
    }
    if(dfs(G,nv,v,g,ans)){
      ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      ans+=x;
      return true;
    }
  }
  return false;
}
int main(){
  ll N;
  cin>>N;
  Graph G(N);
  for(ll i=0;i<N-1;i++){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
    m[make_pair(min(a,b),max(a,b))]=i;
  }
  ll M;
  cin>>M;
  vector<ll> u(M),v(M);
  for(ll i=0;i<M;i++){
    cin>>u.at(i)>>v.at(i);
    u.at(i)--;
    v.at(i)--;
    m[make_pair(min(u.at(i),v.at(i)),max(u.at(i),v.at(i)))]=i;
  }

  vector<ll> edge(M);
  for(ll j=0;j<M;j++){
    dfs(G,u.at(j),-1,v.at(j),edge.at(j));
  }

  vector<ll> num(1<<M,0);
  ll ans=1ull<<(N-1);
  for(ll i=1;i<(1<<M);i++){
    ll bit=i;
    ll C=0;
    ll bit2=0;
    for(ll j=0;j<M;j++){
      if(bit%2==1){
        C++;
        bit2=bit2|edge.at(j);
      }
      bit>>=1;
    }
    ll n=0;
    for(int j=0;j<64;j++){
      n+=bit2%2;
      bit2>>=1;
    }
    num.at(i)=1ull<<(N-1-n);
    if(C%2==1){
      ans-=num.at(i);
    }else{
      ans+=num.at(i);
    }
  }
  cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'bool dfs(Graph&, ll, ll, ll, ll&)':
a.cc:17:34: error: no matching function for call to 'min(ll&, int&)'
   17 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                               ~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:17:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                               ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:17:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                               ~~~^~~~~~
a.cc:17:44: error: no matching function for call to 'max(ll&, int&)'
   17 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                                         ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:17:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                                         ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:17:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                                         ~~~^~~~~~
a.cc:22:34: error: no matching function for call to 'min(ll&, int&)'
   22 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                               ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:22:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   22 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                               ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:22:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   22 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                               ~~~^~~~~~
a.cc:22:44: error: no matching function for call to 'max(ll&, int&)'
   22 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                                         ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:22:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   22 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                                         ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:22:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   22 |       ll x=1ull<<(m[make_pair(min(v,nv),max(v,nv))]);
      |                                         ~~~^~~~~~