Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using Graph = vector<vector<int> >;
using P = pair<int, int>; 
// MOD
//const int mod = 1000000007;
using ll = long long;
long long INF = 1<<30;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
//int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}
 
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}


struct Unionfind{
    vector<int> par;

    Unionfind(int n) : par(n, -1){}

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    } 

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x]>par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

ll sum(ll l, ll r){
    return (l+r)*(r-l+1)/2;
}

ll choose2(ll n){
    return n*(n-1)/2;
}

struct Edge{
    int to, id;
    Edge(int to, int id) : to(to), id(id){}
};

vector<Edge> g[55];
vector<int> es;
bool dfs(int v, int tv, int p=-1){
    if(v == tv){
        es = vector<int>();
        return true;
    }
    for(Edge e : g[v]){
        if(e.to == p) continue;
        if(dfs(e.to, v, tv)){
            es.push_back(e.id);
            return true;
        }
    }
    return false;
}


int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n-1){
        int a, b; cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    
    int m; cin >> m;
    vector<ll> eset(m);
    rep(i,m){
        int a, b; cin >> a >> b;
        a--, b--;
        dfs(a,b);
        for(int e : es){
            eset[i] |= 1ll<<e;
        }
    }
    ll ans = 0;

    rep(i,1<<m){
        ll mask = 0;
        rep(j,m){
            if(i&(j<<1)) mask |= eset[j];
        }
        int white = __builtin_popcountll(mask);
        ll now = 1ll<<(n-1-white);
        if(__builtin_popcountll(i)%2==0) ans+= now;
        else ans -= now;
    }
    cout << ans << endl;
}#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using Graph = vector<vector<int> >;
using P = pair<int, int>; 
// MOD
//const int mod = 1000000007;
using ll = long long;
long long INF = 1<<30;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
//int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}
 
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}


struct Unionfind{
    vector<int> par;

    Unionfind(int n) : par(n, -1){}

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    } 

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x]>par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

ll sum(ll l, ll r){
    return (l+r)*(r-l+1)/2;
}

ll choose2(ll n){
    return n*(n-1)/2;
}

struct Edge{
    int to, id;
    Edge(int to, int id) : to(to), id(id){}
};

vector<Edge> g[55];
vector<int> es;
bool dfs(int v, int tv, int p=-1){
    if(v == tv){
        es = vector<int>();
        return true;
    }
    for(Edge e : g[v]){
        if(e.to == p) continue;
        if(dfs(e.to, v, tv)){
            es.push_back(e.id);
            return true;
        }
    }
    return false;
}


int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n-1){
        int a, b; cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    
    int m; cin >> m;
    vector<ll> eset(m);
    rep(i,m){
        int a, b; cin >> a >> b;
        a--, b--;
        dfs(a,b);
        for(int e : es){
            eset[i] |= 1ll<<e;
        }
    }
    ll ans = 0;

    rep(i,1<<m){
        ll mask = 0;
        rep(j,m){
            if(i&(j<<1)) mask |= eset[j];
        }
        int white = __builtin_popcountll(mask);
        ll now = 1ll<<(n-1-white);
        if(__builtin_popcountll(i)%2==0) ans+= now;
        else ans -= now;
    }
    cout << ans << endl;
}

Compiler output:
a.cc:184:2: error: stray '#' in program
  184 | }#include <iostream>
      |  ^
a.cc:184:3: error: 'include' does not name a type
  184 | }#include <iostream>
      |   ^~~~~~~
a.cc:194:31: error: redefinition of 'template<class T> bool chmax(T&, T)'
  194 | template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
      |                               ^~~~~
a.cc:11:31: note: 'template<class T> bool chmax(T&, T)' previously declared here
   11 | template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
      |                               ^~~~~
a.cc:195:31: error: redefinition of 'template<class T> bool chmin(T&, T)'
  195 | template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
      |                               ^~~~~
a.cc:12:31: note: 'template<class T> bool chmin(T&, T)' previously declared here
   12 | template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
      |                               ^~~~~
a.cc:201:11: error: redefinition of 'long long int INF'
  201 | long long INF = 1<<30;
      |           ^~~
a.cc:18:11: note: 'long long int INF' previously defined here
   18 | long long INF = 1<<30;
      |           ^~~
a.cc:202:11: error: redefinition of 'long long int GCD(long long int, long long int)'
  202 | long long GCD(long long a, long long b) {
      |           ^~~
a.cc:19:11: note: 'long long int GCD(long long int, long long int)' previously defined here
   19 | long long GCD(long long a, long long b) {
      |           ^~~
a.cc:207:11: error: redefinition of 'const int mod'
  207 | const int mod = 998244353;
      |           ^~~
a.cc:24:11: note: 'const int mod' previously defined here
   24 | const int mod = 998244353;
      |           ^~~
a.cc:208:8: error: redefinition of 'struct mint'
  208 | struct mint {
      |        ^~~~
a.cc:25:8: note: previous definition of 'struct mint'
   25 | struct mint {
      |        ^~~~
a.cc:237:10: error: redefinition of 'std::istream& operator>>(std::istream&, const mint&)'
  237 | istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
      |          ^~~~~~~~
a.cc:54:10: note: 'std::istream& operator>>(std::istream&, const mint&)' previously defined here
   54 | istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
      |          ^~~~~~~~
a.cc:238:10: error: redefinition of 'std::ostream& operator<<(std::ostream&, const mint&)'
  238 | ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
      |          ^~~~~~~~
a.cc:55:10: note: 'std::ostream& operator<<(std::ostream&, const mint&)' previously defined here
   55 | ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
      |          ^~~~~~~~
a.cc:241:6: error: redefinition of 'mint f(int)'
  241 | mint f(int n) {
      |      ^
a.cc:58:6: note: 'mint f(int)' previously defined here
   58 | mint f(int n) {
      |      ^
a.cc:249:6: error: redefinition of 'mint choose(int, int)'
  249 | mint choose(int n, int a) {
      |      ^~~~~~
a.cc:66:6: note: 'mint choose(int, int)' previously defined here
   66 | mint choose(int n, int a) {
      |      ^~~~~~
a.cc:258:11: error: redefinition of 'const int dx [4]'
  258 | const int dx[4] = {1, 0, -1, 0};
      |           ^~
a.cc:75:11: note: 'const int dx [4]' previously defined here
   75 | const int dx[4] = {1, 0, -1, 0};
      |           ^~
a.cc:259:11: error: redefinition of 'const int dy [4]'
  259 | const int dy[4] = {0, 1, 0, -1};
      |           ^~
a.cc:76:11: note: 'const int dy [4]' previously defined here
   76 | const int dy[4] = {0, 1, 0, -1};
      |           ^~
a.cc:260:14: error: redefinition of 'const double PI'
  260 | const double PI=3.14159265358979323846;
      |              ^~
a.cc:77:14: note: 'const double PI' previously defined here
   77 | const double PI=3.14159265358979323846;
      |              ^~
a.cc:261:6: error: redefinition of 'bool seen [100][100]'
  261 | bool seen[100][100];
      |      ^~~~
a.cc:78:6: note: 'bool seen [100][100]' previously declared here
   78 | bool seen[100][100];
      |      ^~~~
a.cc:263:6: error: redefinition of 'bool memo [110]'
  263 | bool memo[110];
      |      ^~~~
a.cc:80:6: note: 'bool memo [110]' previously declared here
   80 | bool memo[110];
      |      ^~~~
a.cc:264:6: error: redefinition of 'bool flag'
  264 | bool flag;
      |      ^~~~
a.cc:81:6: note: 'bool flag' previously declared here
   81 | bool flag;
      |      ^~~~
a.cc:265:7: error: redefinition of 'Graph G'
  265 | Graph G;
      |       ^
a.cc:82:7: note: 'Graph G' previously declared here
   82 | Graph G;
      |       ^
a.cc:267:5: error: redefinition of 'int dist [100][100]'
  267 | int dist[100][100];
      |     ^~~~
a.cc:84:5: note: 'int dist [100][100]' previously declared here
   84 | int dist[100][100];
      |     ^~~~
a.cc:269:6: error: redefinition of 'bool compare_f(std::pair<int, int>&, std::pair<int, int>&)'
  269 | bool compare_f(pair<int, int> &x, pair<int, int> &y) {
      |      ^~~~~~~~~
a.cc:86:6: note: 'bool compare_f(std::pair<int, int>&, std::pair<int, int>&)' previously defined here
   86 | bool compare_f(pair<int, int> &x, pair<int, int> &y) {
      |      ^~~~~~~~~
a.cc:274:8: error: redefinition of 'struct Unionfind'
  274 | struct Unionfind{
      |        ^~~~~~~~~
a.cc:91:8: note: previous definition of 'struct Unionfind'
   91 | struct Unionfind{
      |        ^~~~~~~~~
a.cc:302:4: error: redefinition of 'll sum(ll, ll)'
  302 | ll sum(ll l, ll r){
      |    ^~~
a.cc:119:4: note: 'll sum(ll, ll)' previously defined here
  119 | ll sum(ll l, ll r){
      |    ^~~
a.cc:306:4: error: redefinition of 'll choose2(ll)'
  306 | ll choose2(ll n){
      |    ^~~~~~~
a.cc:123:4: note: 'll choose2(ll)' previously defined here
  123 | ll choose2(ll n){
      |    ^~~~~~~
a.cc:310:8: error: redefinition of 'struct Edge'
  310 | struct Edge{
      |        ^~~~
a.cc:127:8: note: previous definition of 'struct Edge'
  127 | struct Edge{
      |        ^~~~
a.cc:315:14: error: redefinition of 'std::vector<Edge> g [55]'
  315 | vector<Edge> g[55];
      |              ^
a.cc:132:14: note: 'std::vector<Edge> g [55]' previously declared here
  132 | vector<Edge> g[55];
      |              ^
a.cc:316:13: error: redefinition of 'std::vector<int> es'
  316 | vector<int> es;
      |             ^~
a.cc:133:13: note: 'std::vector<int> es' previously declared here
  133 | vector<int> es;
      |             ^~
a.cc:317:6: error: redefinition of 'bool dfs(int, int, int)'
  317 | bool dfs(int v, int tv, int p=-1){
      |      ^~~
a.cc:134:6: note: 'bool dfs(int, int, int)' previously defined here
  134 | bool dfs(int v, int tv, int p=-1){
      |      ^~~
a.cc:333:5: error: redefinition of 'int main()'
  333 | int main() {
      |     ^~~~
a.cc:150:5: note: 'int main()' previously defined here
  150 | int main() {
      |     ^~~~