ããã¯ãã¸ã§å¤©æãã¨æããã...
ããæ¬å½ã«ã©ããã Grundy æ°ãå°ããã®ãããããã¬...
åé¡æ¦è¦
é ç¹æ° ã®ã°ã©ãã 3 ã¤ä¸ããããããããã®ã°ã©ãã®ã«ã«ãã·ã¢ã³ç©ãèããããã®é ç¹æ° ã®ã«ã«ãã·ã¢ã³ã°ã©ãã®ç¬ç«éåã®ãã¡ã以ä¸ã®å¤ã®æ大å¤ãæ±ããããã 998244353 ã§å²ã£ããã¾ããæ±ããã
- ç¬ç«éåã«å«ã¾ããåé ç¹ (a, b, c) (ããããã®ã°ã©ãã®é ç¹çªå·ã«ç¸å½, 1-indexed) ã«ã¤ãã¦ãéã¿ã¨ã㦠ãå ç®ãã
å¶ç´
- åã°ã©ãã®è¾ºæ°ã¯ 以ä¸
èãããã¨
ã¾ãã°ã©ãã 1 åã®å ´åãèãã¦ã¿ãã¨ãåç´ã«ãé ç¹çªå·ã大ããé ã« Greedy ã«ã¨ã£ã¦ããã°ãããã¨ããããããã®éã«
- ä»è¦ã¦ããé ç¹ããè¡ããé ç¹ (çªå·ã大ããæ¹åã¸) ã®ãã¡ã
- 1 ã¤ã§ãæ¡ç¨æ¸ã¿ã®é ç¹ããã£ããæ¡ç¨ã§ããªã
- ãã¹ã¦æ¡ç¨ãã¦ããªãé ç¹ã§ããã°æ¡ç¨ãã
ã¨ãã風ã«ããã° OKãããã¦ãã®å¶ã¿ãããªã㨠Game DP ã«ãã£ããã ã¨ããã®ã ãè¨ããã¦ã¿ãã°ç¢ºãã«...
- ãæ¡ç¨æ¸ã¿ãããè² ãã
- ãæ¡ç¨ããªããããåã¡ã
ã¨è¨ãæããã¨ãããã¿ãªå¯¾å¿ããæç¶ãã«ãªã£ã¦ãããããã¦ã«ã«ãã·ã¢ã³ã°ã©ãä¸ã®ãã®æç¶ãã¯ãã3 ã¤ã®å±±ã«é¢ãã Nimãã«å¯¾å¿ããã¨ããã
Grundy æ°
ã¨ããããã§ãããããã®ã°ã©ãã®ããããã®é ç¹ã«ã¤ãã¦ããæ¡ç¨ãããã 0 ã¨ãã¦ãGrundy æ°ãæ±ãã¦ãããã
ããããã¨ãé ç¹ (a, b, c) ãæ¡ç¨ããããã©ããã¯ãGrundy æ°ã® XOR åã 0 ãã©ããã§å¤å®ã§ããã®ã ã
...ã©ãããããããªçºæ³ãçã¾ããã®ãããããªããã©ãã¨ãããããé ç¹ (a, b, c) ãæ¡ç¨ãããããã®å¿ è¦ååæ¡ä»¶ããã£ããèå¯ãããã¨ããã®ãããã¨ããã®ãããããªããããããã¨ããããããèªç¶ã« Grundy æ°ã¨ä¼¼ã¦ãããã¨ã«æãè³ãããGrundy æ°ã¨åçã®æ¦å¿µãèªåã§åçºæã§ããã®ãããããªãã
Grundy æ°ã¯å°ãã
ããã¦ããã«ãGrundy æ°ã¯è¾ºæ°ã ã¨ãã¦ã ç¨åº¦ã®å¤§ããã«ãããªããªãã¨ãããããã¯ããã ã¨æãããã£ã¦ãã®åé¡ã¯ã
- 3 ã¤ã®ã°ã©ãããããã«ã¤ãã¦ãåé ç¹ã® Grundy æ°ãæ±ã
- ããã Grundy æ°ã®å¤ãã¨ã«éè¨ããé åãä½ã (ãã®ãµã¤ãºã¯ ç¨åº¦ã§åå)
- 3 ã¤ã®ãã¡ã® 2 ã¤ã«ã¤ãã¦å ¨æ¢ç´¢ãã¦ãè¨ç®éã¯
ã¨ããããã ã
#include <bits/stdc++.h> using namespace std; template<int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp& r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp& r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; } friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; const int MOD = 998244353; using mint = Fp<MOD>; using Graph = vector<vector<int>>; int N; vector<int> M; vector<Graph> G; vector<mint> ten; void pre() { int MAX = 510000; ten.assign(MAX, 1); mint fac = modpow(mint(10), 18); for (int i = 1; i <= MAX; ++i) ten[i] = ten[i-1] * fac; } mint solve() { vector<vector<int>> grundy(3, vector<int>(N, -1)); vector<vector<mint>> memo(3, vector<mint>(1000, 0)); for (int iter = 0; iter < 3; ++iter) { for (int v = N-1; v >= 0; --v) { set<int> gse; for (auto e : G[iter][v]) gse.insert(grundy[iter][e]); int gres = 0; while (gse.count(gres)) ++gres; grundy[iter][v] = gres; memo[iter][gres] += ten[v+1]; } } mint res = 0; for (int a = 0; a < 1000; ++a) { if (memo[0][a] == 0) break; for (int b = 0; b < 1000; ++b) { if (memo[1][b] == 0) break; int c = a^b; res += memo[0][a] * memo[1][b] * memo[2][c]; } } return res; } int main() { pre(); cin >> N; M.assign(3, 0); G.assign(3, Graph(N, vector<int>())); for (int iter = 0; iter < 3; ++iter) { cin >> M[iter]; for (int i = 0; i < M[iter]; ++i) { int a, b; cin >> a >> b; --a, --b; G[iter][a].push_back(b); G[iter][b].push_back(a); } } cout << solve() << endl; }