44422023-03-28 09:00:05PallanekPéterParti (75 pont)python3Runtime error 51/75167ms34784 KiB
from sys import stdin, stdout
def csokken(j):
    if kihagy[j]==0:
        kihagy[j]=1
        tag[graf[j][0]]-=1
        tag[graf[j][1]]-=1
        if tag[graf[j][0]]<2:
            csokken(graf[j][0])
        if tag[graf[j][1]]<2:
            csokken(graf[j][1])
    return

N=int(input())
tag=[0]*N; kihagy=[0]*N
graf=[]
def main():
    for i in range(N):
        a,b=[int(i) for i in stdin.readline().split()]
        graf.append([a-1,b-1])
        tag[a-1]+=1; tag[b-1]+=1
    for i in range(N):
        if tag[i]<2:
            csokken(i)
    ki=[]
    for i in range(N):
        if tag[i]>1:
            ki.append(i+1)
    print(len(ki))
    print(*ki)
main()
SubtaskSumTestVerdictTimeMemory
base51/75
1Accepted0/018ms10956 KiB
2Accepted0/0159ms30196 KiB
3Accepted3/317ms11656 KiB
4Accepted3/317ms11740 KiB
5Accepted3/317ms11928 KiB
6Accepted3/318ms12384 KiB
7Accepted3/317ms12424 KiB
8Accepted4/418ms12324 KiB
9Accepted4/420ms13036 KiB
10Accepted4/424ms13548 KiB
11Accepted4/420ms13508 KiB
12Accepted4/424ms13960 KiB
13Accepted4/427ms14460 KiB
14Accepted4/428ms15192 KiB
15Accepted4/4158ms32280 KiB
16Runtime error0/4167ms34784 KiB
17Runtime error0/4123ms34700 KiB
18Runtime error0/4119ms34432 KiB
19Runtime error0/4119ms34260 KiB
20Runtime error0/4115ms34344 KiB
21Runtime error0/4118ms34376 KiB
22Accepted4/417ms14048 KiB