[Gold V] Title: ABCDE, Time: 776 ms, Memory: 36064 KB -BaekjoonHub
This commit is contained in:
44
백준/Gold/13023. ABCDE/ABCDE.py
Normal file
44
백준/Gold/13023. ABCDE/ABCDE.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import sys
|
||||
from collections import defaultdict, deque
|
||||
from heapq import heapify, heappush, heappop
|
||||
|
||||
sys.setrecursionlimit(10**6)
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
N, M = map(int, input().split())
|
||||
|
||||
A = defaultdict(list)
|
||||
visited = [False] * (N)
|
||||
max_depth = 0
|
||||
found = False
|
||||
|
||||
for _ in range(M):
|
||||
a, b = map(int, input().split())
|
||||
A[a].append(b)
|
||||
A[b].append(a)
|
||||
|
||||
def DFS(v, depth):
|
||||
global found
|
||||
|
||||
if depth == 4:
|
||||
found=True
|
||||
return
|
||||
|
||||
visited[v] = True
|
||||
for i in A[v]:
|
||||
if not visited[i]:
|
||||
visited[i]= True
|
||||
DFS(i, depth+1)
|
||||
if found :
|
||||
return
|
||||
|
||||
visited[v] = False
|
||||
|
||||
for i in range(N):
|
||||
DFS(i, 0)
|
||||
if found:
|
||||
print(1)
|
||||
break
|
||||
else:
|
||||
print(0)
|
||||
41
백준/Gold/13023. ABCDE/README.md
Normal file
41
백준/Gold/13023. ABCDE/README.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# [Gold V] ABCDE - 13023
|
||||
|
||||
[문제 링크](https://www.acmicpc.net/problem/13023)
|
||||
|
||||
### 성능 요약
|
||||
|
||||
메모리: 36064 KB, 시간: 776 ms
|
||||
|
||||
### 분류
|
||||
|
||||
그래프 이론, 그래프 탐색, 깊이 우선 탐색, 백트래킹
|
||||
|
||||
### 제출 일자
|
||||
|
||||
2026년 3월 30일 18:35:07
|
||||
|
||||
### 문제 설명
|
||||
|
||||
<p>BOJ 알고리즘 캠프에는 총 N명이 참가하고 있다. 사람들은 0번부터 N-1번으로 번호가 매겨져 있고, 일부 사람들은 친구이다.</p>
|
||||
|
||||
<p>오늘은 다음과 같은 친구 관계를 가진 사람 A, B, C, D, E가 존재하는지 구해보려고 한다.</p>
|
||||
|
||||
<ul>
|
||||
<li>A는 B와 친구다.</li>
|
||||
<li>B는 C와 친구다.</li>
|
||||
<li>C는 D와 친구다.</li>
|
||||
<li>D는 E와 친구다.</li>
|
||||
</ul>
|
||||
|
||||
<p>위와 같은 친구 관계가 존재하는지 안하는지 구하는 프로그램을 작성하시오.</p>
|
||||
|
||||
### 입력
|
||||
|
||||
<p>첫째 줄에 사람의 수 N (5 ≤ N ≤ 2000)과 친구 관계의 수 M (1 ≤ M ≤ 2000)이 주어진다.</p>
|
||||
|
||||
<p>둘째 줄부터 M개의 줄에는 정수 a와 b가 주어지며, a와 b가 친구라는 뜻이다. (0 ≤ a, b ≤ N-1, a ≠ b) 같은 친구 관계가 두 번 이상 주어지는 경우는 없다.</p>
|
||||
|
||||
### 출력
|
||||
|
||||
<p>문제의 조건에 맞는 A, B, C, D, E가 존재하면 1을 없으면 0을 출력한다.</p>
|
||||
|
||||
Reference in New Issue
Block a user