結果

問題 No.2780 The Bottle Imp
ユーザー mkawa2mkawa2
提出日時 2024-06-07 22:17:20
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,339 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 72,100 KB
最終ジャッジ日時 2024-12-27 13:56:16
合計ジャッジ時間 12,743 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 29 ms
10,624 KB
testcase_06 AC 29 ms
10,624 KB
testcase_07 AC 401 ms
36,744 KB
testcase_08 AC 400 ms
36,668 KB
testcase_09 AC 412 ms
36,724 KB
testcase_10 AC 366 ms
36,532 KB
testcase_11 AC 378 ms
36,620 KB
testcase_12 AC 949 ms
70,932 KB
testcase_13 AC 934 ms
71,036 KB
testcase_14 AC 155 ms
17,920 KB
testcase_15 AC 154 ms
17,920 KB
testcase_16 AC 158 ms
18,048 KB
testcase_17 AC 152 ms
17,920 KB
testcase_18 AC 159 ms
17,920 KB
testcase_19 AC 157 ms
18,048 KB
testcase_20 AC 156 ms
17,792 KB
testcase_21 AC 157 ms
17,920 KB
testcase_22 AC 138 ms
18,176 KB
testcase_23 AC 148 ms
17,152 KB
testcase_24 AC 309 ms
32,232 KB
testcase_25 AC 632 ms
51,392 KB
testcase_26 AC 245 ms
23,328 KB
testcase_27 AC 209 ms
22,748 KB
testcase_28 AC 219 ms
22,744 KB
testcase_29 AC 251 ms
31,836 KB
testcase_30 AC 264 ms
35,552 KB
testcase_31 AC 396 ms
35,072 KB
testcase_32 AC 97 ms
13,312 KB
testcase_33 AC 452 ms
38,060 KB
testcase_34 AC 761 ms
72,100 KB
testcase_35 AC 87 ms
13,696 KB
testcase_36 AC 33 ms
10,880 KB
testcase_37 AC 32 ms
10,752 KB
testcase_38 AC 88 ms
13,824 KB
testcase_39 AC 331 ms
31,012 KB
testcase_40 AC 341 ms
30,880 KB
testcase_41 AC 343 ms
31,012 KB
testcase_42 WA -
testcase_43 AC 32 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

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)
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)
# print(gg)
# print(nto)
g=u2g[0]
vis=[0]*gn
while vis[g]==0:
vis[g]=1
if len(nto[g])!=1:break
g=nto[g].pop()
print("Yes" if sum(vis)==gn else "No")
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0