Problem p02737 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for (int i = 0; i < (n); i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod = 998244353;
const llint inf = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-10;
template <class T, class U> bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
llint gcd(llint a, llint b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(const vector<T> &ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(const vector<T> &ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}

int main(void) {
  int i, j, n;
  cin >> n;
  llint S = 1000000000000000000LL % mod;

  vector<llint> kei(n);
  kei[0] = S;
  for (i = 0; i < n - 1; i++) {
    kei[i + 1] = kei[i] * S % mod;
  }
  int Lq = 1;
  while (Lq * Lq < n) {
    Lq++;
  }
  Lq *= 2;
  Lq += 10;
  llint L = 1;
  while (L < Lq) {
    L *= 2;
  }
  // cerr<<"L="<<L<<endl;
  vector<llint> ans(L);
  ans[0] = 1;
  for (int kai = 0; kai < 3; kai++) {
    int m;
    cin >> m;
    vector<vector<int>> go(n);
    while (m--) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      if (a < b) {
        swap(a, b);
      }
      go[b].pub(a);
    }
    vector<int> gru(n);
    vector<int> hyo(L, mod);
    vector<llint> gen(L, 0);
    for (i = n - 1; i >= 0; i--) {
      for (auto it : go[i]) {
        hyo[gru[it]] = i;
      }
      int g = 0;
      while (hyo[g] == i) {
        g++;
      }
      gru[i] = g;
      gen[g] += kei[i];
      gen[g] %= mod;
    }
    vector<llint> dp(L, 0);
    for (i = 0; i < L; i++) {
      // cerr<<gen[i]<<endl;
      for (j = 0; j < L; j++) {
        dp[i ^ j] += ans[i] * gen[j];
        dp[i ^ j] %= mod;
      }
    }
    ans = dp;
  }
  cout << ans[0] << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for (int i = 0; i < (n); i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod = 998244353;
const llint inf = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-10;
template <class T, class U> bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
llint gcd(llint a, llint b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(const vector<T> &ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(const vector<T> &ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}

int main(void) {
  int i, j, n;
  cin >> n;
  llint S = 1000000000000000000LL % mod;

  vector<llint> kei(n);
  kei[0] = S;
  for (i = 0; i < n - 1; i++) {
    kei[i + 1] = kei[i] * S % mod;
  }
  llint L = 512;
  // cerr<<"L="<<L<<endl;
  vector<llint> ans(L);
  ans[0] = 1;
  for (int kai = 0; kai < 3; kai++) {
    int m;
    cin >> m;
    vector<vector<int>> go(n);
    while (m--) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      if (a < b) {
        swap(a, b);
      }
      go[b].pub(a);
    }
    vector<int> gru(n);
    vector<int> hyo(L, mod);
    vector<llint> gen(L, 0);
    for (i = n - 1; i >= 0; i--) {
      for (auto it : go[i]) {
        hyo[gru[it]] = i;
      }
      int g = 0;
      while (hyo[g] == i) {
        g++;
      }
      gru[i] = g;
      gen[g] += kei[i];
      gen[g] %= mod;
    }
    vector<llint> dp(L, 0);
    for (i = 0; i < L; i++) {
      // cerr<<gen[i]<<endl;
      for (j = 0; j < L; j++) {
        dp[i ^ j] += ans[i] * gen[j];
        dp[i ^ j] %= mod;
      }
    }
    ans = dp;
  }
  cout << ans[0] << endl;
}