結果
問題 | No.2780 The Bottle Imp |
ユーザー | mkawa2 |
提出日時 | 2024-06-08 17:19:31 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 665 ms / 2,000 ms |
コード長 | 2,320 bytes |
コンパイル時間 | 584 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 71,336 KB |
最終ジャッジ日時 | 2024-06-08 17:19:43 |
合計ジャッジ時間 | 10,620 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
10,752 KB |
testcase_01 | AC | 27 ms
10,752 KB |
testcase_02 | AC | 26 ms
10,752 KB |
testcase_03 | AC | 28 ms
10,880 KB |
testcase_04 | AC | 27 ms
10,752 KB |
testcase_05 | AC | 27 ms
10,880 KB |
testcase_06 | AC | 27 ms
10,752 KB |
testcase_07 | AC | 248 ms
27,392 KB |
testcase_08 | AC | 262 ms
27,392 KB |
testcase_09 | AC | 244 ms
27,520 KB |
testcase_10 | AC | 248 ms
27,392 KB |
testcase_11 | AC | 247 ms
27,520 KB |
testcase_12 | AC | 531 ms
44,164 KB |
testcase_13 | AC | 535 ms
44,264 KB |
testcase_14 | AC | 145 ms
18,048 KB |
testcase_15 | AC | 167 ms
18,048 KB |
testcase_16 | AC | 129 ms
18,048 KB |
testcase_17 | AC | 128 ms
18,048 KB |
testcase_18 | AC | 142 ms
18,048 KB |
testcase_19 | AC | 139 ms
18,048 KB |
testcase_20 | AC | 142 ms
18,048 KB |
testcase_21 | AC | 125 ms
18,048 KB |
testcase_22 | AC | 107 ms
16,512 KB |
testcase_23 | AC | 109 ms
17,152 KB |
testcase_24 | AC | 211 ms
24,448 KB |
testcase_25 | AC | 380 ms
34,484 KB |
testcase_26 | AC | 175 ms
21,248 KB |
testcase_27 | AC | 180 ms
22,748 KB |
testcase_28 | AC | 185 ms
22,616 KB |
testcase_29 | AC | 224 ms
31,776 KB |
testcase_30 | AC | 167 ms
24,960 KB |
testcase_31 | AC | 373 ms
35,072 KB |
testcase_32 | AC | 84 ms
13,440 KB |
testcase_33 | AC | 380 ms
38,316 KB |
testcase_34 | AC | 665 ms
71,336 KB |
testcase_35 | AC | 76 ms
13,696 KB |
testcase_36 | AC | 26 ms
10,752 KB |
testcase_37 | AC | 26 ms
10,880 KB |
testcase_38 | AC | 74 ms
13,568 KB |
testcase_39 | AC | 286 ms
31,008 KB |
testcase_40 | AC | 289 ms
31,008 KB |
testcase_41 | AC | 320 ms
31,140 KB |
testcase_42 | AC | 27 ms
10,752 KB |
testcase_43 | AC | 28 ms
10,752 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")