結果
問題 | No.2435 Order All Company |
ユーザー | yuyu_5510 |
提出日時 | 2023-08-14 23:12:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 240 ms / 2,000 ms |
コード長 | 1,782 bytes |
コンパイル時間 | 343 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 77,696 KB |
最終ジャッジ日時 | 2024-11-23 22:51:52 |
合計ジャッジ時間 | 7,264 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,224 KB |
testcase_01 | AC | 41 ms
52,224 KB |
testcase_02 | AC | 41 ms
51,968 KB |
testcase_03 | AC | 42 ms
52,224 KB |
testcase_04 | AC | 56 ms
62,208 KB |
testcase_05 | AC | 232 ms
77,184 KB |
testcase_06 | AC | 234 ms
77,440 KB |
testcase_07 | AC | 208 ms
77,440 KB |
testcase_08 | AC | 240 ms
77,696 KB |
testcase_09 | AC | 234 ms
77,184 KB |
testcase_10 | AC | 92 ms
76,800 KB |
testcase_11 | AC | 80 ms
70,656 KB |
testcase_12 | AC | 65 ms
65,280 KB |
testcase_13 | AC | 77 ms
70,016 KB |
testcase_14 | AC | 178 ms
77,184 KB |
testcase_15 | AC | 194 ms
77,056 KB |
testcase_16 | AC | 161 ms
76,800 KB |
testcase_17 | AC | 240 ms
77,184 KB |
testcase_18 | AC | 172 ms
77,184 KB |
testcase_19 | AC | 133 ms
76,416 KB |
testcase_20 | AC | 145 ms
76,416 KB |
testcase_21 | AC | 170 ms
77,056 KB |
testcase_22 | AC | 180 ms
77,312 KB |
testcase_23 | AC | 126 ms
76,416 KB |
testcase_24 | AC | 188 ms
77,184 KB |
testcase_25 | AC | 178 ms
77,696 KB |
testcase_26 | AC | 182 ms
77,696 KB |
testcase_27 | AC | 175 ms
76,800 KB |
testcase_28 | AC | 147 ms
76,160 KB |
testcase_29 | AC | 183 ms
77,440 KB |
testcase_30 | AC | 190 ms
77,184 KB |
testcase_31 | AC | 42 ms
52,096 KB |
testcase_32 | AC | 43 ms
52,480 KB |
testcase_33 | AC | 42 ms
52,352 KB |
testcase_34 | AC | 91 ms
73,856 KB |
testcase_35 | AC | 127 ms
76,848 KB |
ソースコード
mod = 998244353 def matrix_tree_theory(mat, N): ret = 1 for i in range(N-1): if mat[i][i] == 0: for j in range(i+1, N-1): if mat[j][i]: for k in range(N-1): mat[i][k], mat[j][k] = mat[j][k], mat[i][k] ret = (-ret + mod) % mod break if mat[i][i] == 0: return 0 for j in range(i+1, N-1): if mat[j][i]: mul = (mat[j][i] * pow(mat[i][i], -1, mod)) % mod for k in range(i, N-1): mat[j][k] = (mat[j][k] - (mul * mat[i][k]) % mod + mod) % mod for i in range(N-1): ret = (ret * mat[i][i]) % mod return ret N, K = map(int, input().split()) G = [[[0 for _ in range(N)] for _ in range(N)] for _ in range(K)] for i in range(K): t = int(input()) for j in range(t): a, b = map(int, input().split()) a -= 1 b -= 1 G[i][a][b] = (G[i][a][b] -1 + mod) % mod G[i][b][a] = (G[i][b][a] -1 + mod) % mod for i in range(K): for j in range(N): sum = 0 for k in range(N): sum += G[i][j][k] sum %= mod sum = (-sum + mod) % mod G[i][j][j] = sum ans = 0 for i in range(1<<K): mat = [[0 for _ in range(N)] for _ in range(N)] cnt = 0 for j in range(K): if i & 1<<j: cnt += 1 for a in range(N): for b in range(N): mat[a][b] += G[j][a][b] mat[a][b] %= mod if (K-cnt) % 2 == 0: ans += matrix_tree_theory(mat, N) ans %= mod else: ans -= matrix_tree_theory(mat, N) ans = (ans + mod) % mod print(ans)