結果
問題 | No.2780 The Bottle Imp |
ユーザー | mkawa2 |
提出日時 | 2024-06-08 17:19:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 228 ms / 2,000 ms |
コード長 | 2,320 bytes |
コンパイル時間 | 280 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 134,400 KB |
最終ジャッジ日時 | 2024-06-08 17:19:28 |
合計ジャッジ時間 | 6,928 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,736 KB |
testcase_01 | AC | 38 ms
52,352 KB |
testcase_02 | AC | 37 ms
52,352 KB |
testcase_03 | AC | 42 ms
52,736 KB |
testcase_04 | AC | 42 ms
52,224 KB |
testcase_05 | AC | 41 ms
52,480 KB |
testcase_06 | AC | 41 ms
52,352 KB |
testcase_07 | AC | 164 ms
89,088 KB |
testcase_08 | AC | 199 ms
89,344 KB |
testcase_09 | AC | 162 ms
88,960 KB |
testcase_10 | AC | 172 ms
89,984 KB |
testcase_11 | AC | 161 ms
88,832 KB |
testcase_12 | AC | 228 ms
102,684 KB |
testcase_13 | AC | 226 ms
103,128 KB |
testcase_14 | AC | 133 ms
82,944 KB |
testcase_15 | AC | 114 ms
82,688 KB |
testcase_16 | AC | 111 ms
82,432 KB |
testcase_17 | AC | 109 ms
82,816 KB |
testcase_18 | AC | 112 ms
82,560 KB |
testcase_19 | AC | 110 ms
82,688 KB |
testcase_20 | AC | 110 ms
82,688 KB |
testcase_21 | AC | 109 ms
82,560 KB |
testcase_22 | AC | 126 ms
80,768 KB |
testcase_23 | AC | 112 ms
82,048 KB |
testcase_24 | AC | 158 ms
89,216 KB |
testcase_25 | AC | 211 ms
99,584 KB |
testcase_26 | AC | 136 ms
85,248 KB |
testcase_27 | AC | 120 ms
93,184 KB |
testcase_28 | AC | 120 ms
93,056 KB |
testcase_29 | AC | 135 ms
97,280 KB |
testcase_30 | AC | 104 ms
86,400 KB |
testcase_31 | AC | 167 ms
101,632 KB |
testcase_32 | AC | 77 ms
79,488 KB |
testcase_33 | AC | 165 ms
119,040 KB |
testcase_34 | AC | 200 ms
134,400 KB |
testcase_35 | AC | 90 ms
77,440 KB |
testcase_36 | AC | 38 ms
52,736 KB |
testcase_37 | AC | 39 ms
52,736 KB |
testcase_38 | AC | 91 ms
77,568 KB |
testcase_39 | AC | 160 ms
101,504 KB |
testcase_40 | AC | 152 ms
101,248 KB |
testcase_41 | AC | 166 ms
101,248 KB |
testcase_42 | AC | 39 ms
52,480 KB |
testcase_43 | AC | 40 ms
52,352 KB |
ソースコード
import sys # sys.setrecursionlimit(1000006) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = -1-(-1 << 31) # inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 n=II() to=[[] for _ in range(n)] for u in range(n): vv=LI1() to[u]=vv[1:] ot=[[] for _ in range(n)] for u in range(n): for v in to[u]: ot[v].append(u) # 各強連結成分をリストにしてトポロジカル順に返す def SCC(to, ot): n = len(to) # トポロジカルソート fin = [-1]*n topo = [] for u in range(n): if fin[u] != -1: continue stack = [u] while stack: u = stack[-1] if fin[u] == -1: fin[u] = 0 for v in to[u]: if fin[v] != -1: continue stack.append(v) else: stack.pop() if fin[u] == 0: fin[u] = 1 topo.append(u) # 逆辺でdfs res = [] while topo: u = topo.pop() if fin[u] != 1: continue fin[u] = 2 cur = [u] i = 0 while i < len(cur): u = cur[i] for v in ot[u]: if fin[v] == 2: continue fin[v] = 2 cur.append(v) i += 1 res.append(cur) return res gg=SCC(to,ot) if 0 not in gg[0]: print("No") exit() gn=len(gg) u2g=[0]*n for g,uu in enumerate(gg): for u in uu:u2g[u]=g nto=[set() for _ in range(gn)] for u in range(n): f=u2g[u] for v in to[u]: g=u2g[v] if g==f:continue nto[f].add(g) for i in range(gn-1): if i+1 not in nto[i]: print("No") exit() print("Yes")