結果
問題 | No.2435 Order All Company |
ユーザー | 👑 SPD_9X2 |
提出日時 | 2023-08-18 22:23:35 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,168 bytes |
コンパイル時間 | 217 ms |
コンパイル使用メモリ | 82,276 KB |
実行使用メモリ | 120,264 KB |
最終ジャッジ日時 | 2024-05-06 04:38:31 |
合計ジャッジ時間 | 7,705 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,864 KB |
testcase_01 | AC | 35 ms
52,352 KB |
testcase_02 | AC | 36 ms
52,224 KB |
testcase_03 | AC | 36 ms
52,480 KB |
testcase_04 | AC | 53 ms
64,128 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 63 ms
71,296 KB |
testcase_12 | AC | 55 ms
67,328 KB |
testcase_13 | AC | 74 ms
76,032 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 118 ms
96,128 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 118 ms
91,428 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 34 ms
52,096 KB |
testcase_32 | AC | 34 ms
52,096 KB |
testcase_33 | AC | 34 ms
52,096 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
ソースコード
""" 包除原理+行列木定理 """ import sys from sys import stdin def Detmod(a,mod = 10**18+3): assert len(a) == len(a[0]) n = len(a) b = [[a[i][j] for j in range(n)] for i in range(n)] ret = 1 for x in range(n): ret *= b[x][x] ret %= mod if b[x][x] == 0: return 0 inv = pow(b[x][x],mod-2,mod) for i in range(x+1,n): mul = b[i][x] * inv for j in range(x,n): b[i][j] -= b[x][j] * mul b[i][j] %= mod return ret # need Detmod class MatrixTreeTheorem(): def __init__(self): self.vdic = {} self.edges = [] def add_vertex(self,v): if v not in self.vdic: self.vdic[v] = len(self.vdic) return def add_edge(self,u,v): assert u in self.vdic assert v in self.vdic if u == v: return self.edges.append( (self.vdic[u],self.vdic[v]) ) def calc(self, mod = 10**18+3): if len(self.vdic) == 0: return 1 elif len(self.vdic) == 1: return 1 H = [[0] * len(self.vdic) for i in range(len(self.vdic))] for u2,v2 in self.edges: H[u2][u2] += 1 H[v2][v2] += 1 H[v2][u2] -= 1 H[u2][v2] -= 1 for i in range(len(self.vdic)): del H[i][-1] del H[-1] return Detmod(H,mod) mod = 998244353 N,K = map(int,stdin.readline().split()) ab = [ [] for i in range(K) ] for lp in range(K): t = int(stdin.readline()) for i in range(t): a,b = map(int,stdin.readline().split()) a -= 1 b -= 1 ab[lp].append( (a,b) ) ans = 0 for bit in range(2**K): zero = 0 for i in range(K): if 2**i & bit == 0: zero += 1 mt = MatrixTreeTheorem() for i in range(N): mt.add_vertex(i) for i in range(K): if 2**i & bit > 0: for a,b in ab[i]: mt.add_edge(a,b) now = mt.calc() if zero % 2 == 0: ans += now else: ans -= now print (ans % mod)