Problem p02737 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

const int MaxN = 100000, MaxS = 350;
const int Mod = 998244353, base = ((long long)1e18) % Mod;

int N;
int Pw[MaxN + 5];
int Sg[3][MaxN + 5];
std::vector<int> Gr[3][MaxN + 5];
int Buc[3][MaxS + 5];

inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % Mod; }
inline void inc(int &x, int y = 1) { x = add(x, y); }

void init() {
  scanf("%d", &N);
  Pw[0] = 1;
  for (int i = 1; i <= N; ++i)
    Pw[i] = mul(Pw[i - 1], base);
  for (int k = 0; k < 3; ++k) {
    int m;
    scanf("%d", &m);
    for (int i = 1; i <= m; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      if (u > v)
        std::swap(u, v);
      Gr[k][u].push_back(v);
    }
  }
}

void getSg(int k) {
  static bool buc[MaxN + 5];
  memset(buc, false, sizeof buc);
  int mx = 0;
  for (int u = N; u >= 1; --u) {
    for (int i = 0; i <= mx; ++i)
      buc[i] = false;
    mx = 0;
    for (int v : Gr[k][u]) {
      buc[Sg[k][v]] = true;
      mx = std::max(mx, Sg[k][v]);
    }
    for (int i = 0; i <= mx + 1; ++i)
      if (buc[i] == false) {
        Sg[k][u] = i;
        break;
      }
  }
}

void solve() {
  for (int k = 0; k < 3; ++k)
    getSg(k);
  for (int k = 0; k < 3; ++k)
    for (int i = 1; i <= N; ++i)
      inc(Buc[k][Sg[k][i]], Pw[i]);
  int ans = 0;
  for (int i = 0; i <= MaxS; ++i)
    for (int j = 0; j <= MaxS; ++j) {
      int k = i ^ j;
      inc(ans, mul(mul(Buc[0][i], Buc[1][j]), Buc[2][k]));
    }
  printf("%d\n", ans);
}

int main() {
  init();
  solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

const int MaxN = 100000, MaxS = 1000;
const int Mod = 998244353, base = ((long long)1e18) % Mod;

int N;
int Pw[MaxN + 5];
int Sg[3][MaxN + 5];
std::vector<int> Gr[3][MaxN + 5];
int Buc[3][MaxS + 5];

inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % Mod; }
inline void inc(int &x, int y = 1) { x = add(x, y); }

void init() {
  scanf("%d", &N);
  Pw[0] = 1;
  for (int i = 1; i <= N; ++i)
    Pw[i] = mul(Pw[i - 1], base);
  for (int k = 0; k < 3; ++k) {
    int m;
    scanf("%d", &m);
    for (int i = 1; i <= m; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      if (u > v)
        std::swap(u, v);
      Gr[k][u].push_back(v);
    }
  }
}

void getSg(int k) {
  static bool buc[MaxN + 5];
  memset(buc, false, sizeof buc);
  int mx = 0;
  for (int u = N; u >= 1; --u) {
    for (int i = 0; i <= mx; ++i)
      buc[i] = false;
    mx = 0;
    for (int v : Gr[k][u]) {
      buc[Sg[k][v]] = true;
      mx = std::max(mx, Sg[k][v]);
    }
    for (int i = 0; i <= mx + 1; ++i)
      if (buc[i] == false) {
        Sg[k][u] = i;
        break;
      }
  }
}

void solve() {
  for (int k = 0; k < 3; ++k)
    getSg(k);
  for (int k = 0; k < 3; ++k)
    for (int i = 1; i <= N; ++i)
      inc(Buc[k][Sg[k][i]], Pw[i]);
  int ans = 0;
  for (int i = 0; i <= MaxS; ++i)
    for (int j = 0; j <= MaxS; ++j) {
      int k = i ^ j;
      inc(ans, mul(mul(Buc[0][i], Buc[1][j]), Buc[2][k]));
    }
  printf("%d\n", ans);
}

int main() {
  init();
  solve();
  return 0;
}