run2ai / algorithm-taek

0 stars 0 forks source link

친구 관계 파악하기 #26

Closed Blzae97 closed 3 months ago

Blzae97 commented 3 months ago

시간 제한: 2초 난이도: 골드V 백준 온라인 저지: 13023번 https://www.acmicpc.net/problem/13023

teang1995 commented 3 months ago
# https://www.acmicpc.net/problem/13023

import sys
from sys import stdin as s
sys.setrecursionlimit(10**6)

result = 0
n, m = map(int, s.readline().split())
network = [[] for _ in range(n)]
visited = [False] * n

for _ in range(m):
    a,b = map(int, s.readline().split())
    network[a].append(b)
    network[b].append(a)

def dfs(start, cnt):
    global result
    visited[start] = True
    cnt +=1

    if  cnt == 5:
        result = 1
        return 

    for f in network[start]:
        if visited[f] == False :
            visited[f] = True
            dfs(f, cnt)

    visited[start] = False

for i in range(n):
    if result == 1 :
        break
    dfs(i, 0)

print(result)