# swea 1219 '길찾기'

def check_way(edges, visits, node):
    if node == 99:
        return 1

    for next_node in edges[node]:
        if visits[next_node]:
            continue

        visits[next_node] = True
        if check_way(edges, visits, next_node):
            return 1

    return 0


if __name__ == '__main__':
    T = 10

    for _ in range(1, T+1):
        t, n = map(int, input().split())

        edges = [list() for _ in range(100)]
        visits = [False for _ in range(100)]

        input_list = list(map(int, input().split()))
        for i in range(n):
            v1 = input_list[2 * i]
            v2 = input_list[2 * i + 1]

            edges[v1].append(v2)

        visits[0] = True
        result = check_way(edges, visits, 0)

        print('#{} {}'.format(t, result))

'알고리즘 문제 풀이 > SWEA' 카테고리의 다른 글

[SWEA 1224 python] 계산기3  (0) 2021.08.24
[SWEA 1223 python] 계산기2  (0) 2021.08.23
[SWEA 1234 python] 비밀번호  (0) 2021.08.19
[SWEA 2005 python] 파스칼의 삼각형  (0) 2021.08.18
[SWEA 1216 python] 회문2  (0) 2021.08.17

+ Recent posts