Submission #7564192


Source Code Expand

from collections import deque

N,M = map(int, input().split())

es_lang = [[] for _ in range(M+1)] # 各言語の番号がidxで、それを話せる人が中身
es_p = [[] for _ in range(N+1)] # 各人の番号がidxで、その人の話せる言語が中身
for i in range(N):
    KL = list(map(int, input().split()))
    es_p[i+1].extend(KL[1:])
    for j in KL[1:]:
        es_lang[j].append(i+1)

checked_lang = [False] * (M+1)
checked_p = [False] * (N+1)

#人1からスタートする
stack_p = [1]
checked_p[1] = True
while len(stack_p) > 0:
    new_stack_p = [] # この次のループで調べる人の集合
    for p in stack_p:
        checked_p[p] = True
        stack_lang = []
        for lang in es_p[p]: #人pが話せる言語について調べる
            if checked_lang[lang] == False: # まだその言語を調査してないとき
                stack_lang.append(lang)
                checked_lang[lang] = True

        # 人pの持つ言語をだれが話せるか調べる
        for lang in stack_lang:
            for pp in es_lang[lang]: # 人pの話せる言語を話せる人について調べる
                if checked_p[pp] == False: # まだその人を調べてないなら次のループで調べる人に入れる
                    new_stack_p.append(pp)
                    checked_p[pp] = True

    if all(checked_p[1:]):
        print("YES")
        exit()
    if len(new_stack_p) > 0:
        stack_p = new_stack_p
    else:
        break



print("NO")

Submission Info

Submission Time
Task C - Interpretation
User nejiyoshida
Language Python (3.4.3)
Score 400
Code Size 1560 Byte
Status AC
Exec Time 637 ms
Memory 38832 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 27
Set Name Test Cases
sample sample-01.txt, sample-02.txt
dataset1 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt
dataset2 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt AC 21 ms 3316 KB
01-02.txt AC 23 ms 3444 KB
01-03.txt AC 26 ms 3572 KB
01-04.txt AC 26 ms 3572 KB
01-05.txt AC 26 ms 3572 KB
01-06.txt AC 25 ms 3572 KB
01-07.txt AC 25 ms 3444 KB
01-08.txt AC 25 ms 3572 KB
01-09.txt AC 25 ms 3444 KB
01-10.txt AC 26 ms 3700 KB
02-01.txt AC 253 ms 22184 KB
02-02.txt AC 596 ms 28620 KB
02-03.txt AC 213 ms 18056 KB
02-04.txt AC 566 ms 28036 KB
02-05.txt AC 579 ms 26140 KB
02-06.txt AC 519 ms 28028 KB
02-07.txt AC 637 ms 28096 KB
02-08.txt AC 476 ms 27388 KB
02-09.txt AC 519 ms 38832 KB
02-10.txt AC 289 ms 26076 KB
02-11.txt AC 321 ms 25468 KB
02-12.txt AC 383 ms 24628 KB
02-13.txt AC 366 ms 24512 KB
sample-01.txt AC 21 ms 3316 KB
sample-02.txt AC 21 ms 3316 KB