728x90
#13023번 ABCDE https://www.acmicpc.net/problem/13023
13023번: ABCDE
문제의 조건에 맞는 A, B, C, D, E가 존재하면 1을 없으면 0을 출력한다.
www.acmicpc.net
처음에는 모든 노드가 다음 단계 노드로 연결될 수 있음을 검증하는거라 생각했다.
그래서 엄청 열심히 풀었는데 Recursion Error나와서 진짜 짜증났다...
그래서 검색했더니 그냥 깊이가 4인 노트 찾는거란다.......
ABCDE이래서 되게 헷갈렸던..
백준의 단점이라 하면 부족한 설명이 아닌가 싶다.
from operator import ne
import sys
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
prev, to = map(int, sys.stdin.readline().split())
graph[prev].append(to)
graph[to].append(prev)
visited = [False]*N
def dfs(idx, depth):
if depth == 4:
print(1)
exit()
for neighbour in graph[idx]:
if not visited[neighbour]:
visited[neighbour] = True
dfs(neighbour, depth+1)
visited[neighbour] = False
for i in range(N):
visited[i] = True
dfs(i, 0)
visited[i] = False
print(0)
'Algorithm > acmicpc.net' 카테고리의 다른 글
실버는 무난하게... 아..아니? (0) | 2022.01.23 |
---|---|
고... 골드가 풀린다!... (0) | 2022.01.22 |
비트마스크 (0) | 2022.01.21 |
골드의 길은 멀고도 험하다 (0) | 2022.01.20 |
스타트와 링크 링크와 스타트 (0) | 2022.01.19 |