Submission #69492211


Source Code Expand

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N = int(input())
activate = [[] for v in range(N)]
done = [0] * N
deq = deque()
for i in range(N):
    a,b = mi()
    if (a,b) == (0,0):
        done[i] = 1
        deq.append(i)
    else:
        activate[a-1].append(i)
        activate[b-1].append(i)

while deq:
    v = deq.popleft()
    for nv in activate[v]:
        if not done[nv]:
            deq.append(nv)
            done[nv] = 1

print(sum(done))

Submission Info

Submission Time
Task C - New Skill Acquired
User chinerist
Language Python (PyPy 3.10-v7.3.12)
Score 300
Code Size 720 Byte
Status AC
Exec Time 271 ms
Memory 108452 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 30
Set Name Test Cases
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
Case Name Status Exec Time Memory
hand_01.txt AC 88 ms 83288 KiB
hand_02.txt AC 89 ms 83364 KiB
random_01.txt AC 213 ms 107192 KiB
random_02.txt AC 111 ms 85408 KiB
random_03.txt AC 254 ms 107660 KiB
random_04.txt AC 208 ms 101968 KiB
random_05.txt AC 251 ms 107304 KiB
random_06.txt AC 203 ms 102436 KiB
random_07.txt AC 241 ms 107328 KiB
random_08.txt AC 129 ms 97584 KiB
random_09.txt AC 212 ms 108216 KiB
random_10.txt AC 237 ms 108452 KiB
random_11.txt AC 155 ms 108348 KiB
random_12.txt AC 252 ms 108404 KiB
random_13.txt AC 248 ms 107968 KiB
random_14.txt AC 271 ms 108376 KiB
random_15.txt AC 247 ms 108420 KiB
random_16.txt AC 138 ms 94212 KiB
random_17.txt AC 256 ms 105548 KiB
random_18.txt AC 115 ms 87428 KiB
random_19.txt AC 168 ms 96152 KiB
random_20.txt AC 190 ms 101324 KiB
random_21.txt AC 101 ms 84764 KiB
random_22.txt AC 131 ms 89052 KiB
random_23.txt AC 225 ms 102996 KiB
random_24.txt AC 139 ms 91804 KiB
random_25.txt AC 183 ms 96488 KiB
random_26.txt AC 98 ms 84756 KiB
sample_01.txt AC 88 ms 83228 KiB
sample_02.txt AC 88 ms 83364 KiB