提出 #69504107


ソースコード 拡げる

n = int(input())
a, b = zip(*[tuple(map(int, input().split())) for _ in range(n)])

is_skill = [False] * (n + 1)
start = []
g = [set() for _ in range(n + 1)]
for i in range(n):
    if a[i] == 0 and b[i] == 0:
        is_skill[i + 1] = True
        start.append(i + 1)
    else:
        if i + 1 != a[i]:
            g[i + 1].add(a[i])
            g[a[i]].add(i + 1)
        if i + 1 != b[i]:
            g[i + 1].add(b[i])

            g[b[i]].add(i + 1)

used = [False] * (n + 1)
while len(start) > 0:
    v = start.pop()
    if not used[v]:
        used[v] = True
        is_skill[v] = True
        for w in g[v]:
            if not used[w]:
                start.append(w)

ans = 0
for i in range(1, n + 1):
    if is_skill[i]:
        ans += 1

print(ans)

提出情報

提出日時
問題 C - New Skill Acquired
ユーザ suidonx
言語 Python (PyPy 3.10-v7.3.12)
得点 0
コード長 795 Byte
結果 WA
実行時間 484 ms
メモリ 179252 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 300
結果
AC × 2
AC × 21
WA × 9
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 56 ms 76560 KiB
hand_02.txt AC 58 ms 76400 KiB
random_01.txt AC 316 ms 161024 KiB
random_02.txt AC 100 ms 84504 KiB
random_03.txt AC 423 ms 177784 KiB
random_04.txt AC 340 ms 150680 KiB
random_05.txt AC 448 ms 177756 KiB
random_06.txt AC 296 ms 147740 KiB
random_07.txt AC 484 ms 179252 KiB
random_08.txt AC 181 ms 126344 KiB
random_09.txt AC 366 ms 162292 KiB
random_10.txt AC 383 ms 177488 KiB
random_11.txt AC 252 ms 175768 KiB
random_12.txt AC 398 ms 168728 KiB
random_13.txt AC 366 ms 162364 KiB
random_14.txt AC 405 ms 162648 KiB
random_15.txt AC 431 ms 161788 KiB
random_16.txt AC 194 ms 118784 KiB
random_17.txt WA 379 ms 160440 KiB
random_18.txt WA 125 ms 90472 KiB
random_19.txt WA 230 ms 122944 KiB
random_20.txt WA 295 ms 143756 KiB
random_21.txt WA 84 ms 82756 KiB
random_22.txt WA 156 ms 95936 KiB
random_23.txt WA 382 ms 168576 KiB
random_24.txt WA 160 ms 106856 KiB
random_25.txt WA 218 ms 124396 KiB
random_26.txt AC 83 ms 84244 KiB
sample_01.txt AC 57 ms 76592 KiB
sample_02.txt AC 56 ms 76620 KiB