結果
問題 | No.2435 Order All Company |
ユーザー | 👑 SPD_9X2 |
提出日時 | 2023-08-18 22:23:35 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,168 bytes |
コンパイル時間 | 465 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 120,004 KB |
最終ジャッジ日時 | 2024-11-28 08:07:35 |
合計ジャッジ時間 | 8,484 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
52,480 KB |
testcase_01 | AC | 46 ms
52,352 KB |
testcase_02 | AC | 46 ms
52,480 KB |
testcase_03 | AC | 42 ms
52,480 KB |
testcase_04 | AC | 56 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 | 72 ms
71,772 KB |
testcase_12 | AC | 61 ms
67,200 KB |
testcase_13 | AC | 86 ms
75,904 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 124 ms
96,000 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 | 124 ms
91,560 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 37 ms
52,864 KB |
testcase_32 | AC | 37 ms
52,608 KB |
testcase_33 | AC | 37 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)