44942023-03-29 10:15:24PallanekPéterParti (75 pont)python3Runtime error 51/75174ms35344 KiB
import sys
sys.setrecursionlimit(10 ** 9)
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 sys.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/017ms11104 KiB
2Accepted0/0167ms30452 KiB
3Accepted3/317ms11660 KiB
4Accepted3/317ms11844 KiB
5Accepted3/317ms12028 KiB
6Accepted3/317ms12120 KiB
7Accepted3/317ms12088 KiB
8Accepted4/418ms12648 KiB
9Accepted4/420ms13040 KiB
10Accepted4/424ms13480 KiB
11Accepted4/420ms13104 KiB
12Accepted4/424ms13344 KiB
13Accepted4/426ms14200 KiB
14Accepted4/429ms14412 KiB
15Accepted4/4165ms31784 KiB
16Runtime error0/4174ms35344 KiB
17Runtime error0/4129ms35208 KiB
18Runtime error0/4135ms35328 KiB
19Runtime error0/4133ms35060 KiB
20Runtime error0/4129ms35048 KiB
21Runtime error0/4128ms35048 KiB
22Accepted4/417ms13868 KiB