PAT 1090 marchandises dangereuses Grade B emballage

Le code a été libéré, nous apprenons ensemble, entraidons
Titre:
Insérer ici l'image Description
Exemple d' entrée:

6 3
20001 20002
20003 20004
20005 20006
20003 20001
20005 20004
20004 20006
4 00001 20004 00002 20003
5 98823 20002 20003 20006 10010
3 12345 67890 23333

Exemple de sortie:

No
Yes
Yes

Code ci-dessous (Python):

x, y = (int(x) for x in input().split())
forbidden = {}
for i in range(x):
    alice, bob = (i for i in input().split())
    forbidden.setdefault(alice, [])
    forbidden[alice].append(bob)
    forbidden.setdefault(bob, [])
    forbidden[bob].append(alice)
for i in range(y):
    temp = [z for z in input().split()]
    answer = 'Yes'
    for alice in temp[1:]:
        if alice in forbidden:
            for bob in forbidden[alice]:
                if bob in temp:
                    answer = 'No'
                    break
        if answer == 'No':
            break
    print(answer)
Publié 65 articles originaux · louange gagné 25 · vues 1025

Je suppose que tu aimes

Origine blog.csdn.net/chongchujianghu3/article/details/104987372
conseillé
Classement