[Python] BOJ 13023번. ABCDE

13023번. ABCDE

문제 링크

풀이 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 13023번. ABCDE


import sys
input = sys.stdin.readline

n, m = map(int, input().split())
box = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    box[a].append(b)
    box[b].append(a)

visited = [False for i in range(n)]


def dfs(index, cnt):
    global ans

    visited[index] = True

    if(cnt == 4):
        ans = True
        return

    for v in box[index]:
        if not visited[v]:
            dfs(v, cnt+1)
            visited[v] = False


ans = False
for i in range(n):
    dfs(i, 0)
    visited[i] = False
    if ans:
        break

print(1 if ans else 0)

비고