Submission #7564098


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:
    for p in stack_p:
        stack_lang = []
        for lang in es_p[p]: #人pが話せる言語について調べる
            if checked_lang[lang] == False: # まだその言語を調査してないとき
                stack_lang.append(lang)
                checked_lang[lang] = True

        # 人pの持つ言語をだれが話せるか調べる
        new_stack_p = []
        for lang in stack_lang:
            for pp in es_lang[lang]:
                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 0
Code Size 1338 Byte
Status WA
Exec Time 493 ms
Memory 38832 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 0 / 200 0 / 200
Status
AC × 2
AC × 8
WA × 4
AC × 18
WA × 9
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 WA 22 ms 3444 KB
01-03.txt AC 25 ms 3572 KB
01-04.txt AC 25 ms 3572 KB
01-05.txt AC 24 ms 3572 KB
01-06.txt WA 23 ms 3572 KB
01-07.txt WA 23 ms 3444 KB
01-08.txt AC 23 ms 3572 KB
01-09.txt WA 23 ms 3444 KB
01-10.txt AC 25 ms 3700 KB
02-01.txt WA 142 ms 22056 KB
02-02.txt AC 469 ms 27848 KB
02-03.txt AC 144 ms 17928 KB
02-04.txt WA 340 ms 28036 KB
02-05.txt WA 405 ms 25628 KB
02-06.txt AC 353 ms 27956 KB
02-07.txt WA 446 ms 28100 KB
02-08.txt AC 455 ms 27388 KB
02-09.txt AC 493 ms 38832 KB
02-10.txt AC 279 ms 26080 KB
02-11.txt AC 317 ms 25468 KB
02-12.txt WA 292 ms 24508 KB
02-13.txt AC 289 ms 24264 KB
sample-01.txt AC 21 ms 3316 KB
sample-02.txt AC 21 ms 3316 KB