71802024-01-01 23:35:13KezdőElágazás nélküli úton levő települések (50 pont)python3Wrong answer 35/50266ms21332 KiB
from sys import stdin

def main():
    N,M = [int(i) for i in input().split()]
    U = [[] for i in range(N+1)]
    for i in range(M):
        a,b = [int(i) for i in stdin.readline().split()]
        if b not in U[a]:
            U[a].append(b)
        if a not in U[b]:
            U[b].append(a)
    zs = [i for i in range(1,N+1) if len(U[i]) == 1]
    ent = []
    for zsak in zs:
        falu = U[zsak][0]
        if falu not in ent:
            ent.append(falu)
        elozo = zsak
        while len(U[falu]) == 2:
            if U[falu][0] == elozo:
                elozo,falu = U[falu]
            else:
                falu,elozo = U[falu]
            if falu not in ent:
                ent.append(falu)
        if falu not in ent:
            ent.append(falu)
    print(len(ent))
    if ent != []:
        ent.sort()
        print(*ent)
main()    
SubtaskSumTestVerdictTimeMemory
base35/50
1Accepted0/017ms11364 KiB
2Accepted0/082ms19676 KiB
3Accepted2/217ms11676 KiB
4Accepted2/217ms11440 KiB
5Accepted2/217ms11892 KiB
6Accepted2/217ms11972 KiB
7Accepted2/217ms12228 KiB
8Accepted2/221ms13132 KiB
9Accepted2/227ms13944 KiB
10Accepted2/234ms14640 KiB
11Accepted2/250ms16292 KiB
12Accepted2/250ms16480 KiB
13Wrong answer0/320ms12876 KiB
14Time limit exceeded0/3231ms5252 KiB
15Wrong answer0/328ms13904 KiB
16Time limit exceeded0/3266ms6152 KiB
17Wrong answer0/346ms16924 KiB
18Accepted3/350ms17312 KiB
19Accepted3/354ms18344 KiB
20Accepted3/382ms21184 KiB
21Accepted3/383ms21332 KiB
22Accepted3/383ms21148 KiB