Submission #7564002


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 = deque([1])
checked_p[1] = True
while stack_p:
    p = stack_p.pop() # 調べる人を取り出す
    #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
    #print(p, "lll", stack_lang)
    # 人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
    #print("--", checked_p, checked_lang)
    #print("^^^", new_stack_p)
    if all(checked_p[1:]):
        print("YES")
        """
        print(checked_p)
        print(checked_lang)
        print(es_p)
        """
        exit()
    for i in new_stack_p:
        stack_p.append(i)

print("NO")
"""
print(checked_p)
print(checked_lang)
print(es_p)
"""

Submission Info

Submission Time
Task C - Interpretation
User nejiyoshida
Language Python (3.4.3)
Score 200
Code Size 1576 Byte
Status TLE
Exec Time 2106 ms
Memory 38832 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 0 / 200
Status
AC × 2
AC × 12
AC × 18
TLE × 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 AC 22 ms 3444 KB
01-03.txt AC 25 ms 3700 KB
01-04.txt AC 27 ms 3572 KB
01-05.txt AC 28 ms 3572 KB
01-06.txt AC 26 ms 3572 KB
01-07.txt AC 25 ms 3444 KB
01-08.txt AC 25 ms 3572 KB
01-09.txt AC 26 ms 3444 KB
01-10.txt AC 25 ms 3700 KB
02-01.txt AC 239 ms 22056 KB
02-02.txt TLE 2106 ms 28024 KB
02-03.txt AC 708 ms 18056 KB
02-04.txt TLE 2106 ms 28036 KB
02-05.txt TLE 2106 ms 25684 KB
02-06.txt TLE 2106 ms 28028 KB
02-07.txt TLE 2106 ms 28096 KB
02-08.txt TLE 2106 ms 27388 KB
02-09.txt AC 510 ms 38832 KB
02-10.txt AC 287 ms 26076 KB
02-11.txt TLE 2106 ms 25404 KB
02-12.txt TLE 2106 ms 24628 KB
02-13.txt TLE 2106 ms 24384 KB
sample-01.txt AC 20 ms 3316 KB
sample-02.txt AC 20 ms 3316 KB