재귀 3

백준[Python] 13023.ABCDE - 파이썬

📖 문제 📃 코드 import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline N, M = map(int, input().split()) relation = [[] for i in range(N)] visited = [False] * (N+1) ans = False for i in range(M): a, b = map(int, input().split()) relation[a].append(b) relation[b].append(a) def dfs(idx, depth): global ans visited[idx] = True # 1. 종료조건 # case A-B-C-D-E 같은 친구 관계가 있는지 검사 if depth == 4: ans = Tru..

백준[Python] 11724.연결 요소의 개수 - 파이썬

📖 문제 📃 코드 import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline N, M = map(int, input().split()) matrix = [[0]*(N+1) for i in range(N+1)] visited = [False] * (N+1) for i in range(M): a, b = map(int, input().split()) matrix[a][b] = matrix[b][a] = 1 def dfs(v): visited[v] = True for node in range(len(matrix[v])): if visited[node] == False and matrix[v][node] == 1: dfs(node) cnt = 0 fo..

백준[JAVA] 2609.최대공약수와 최소공배수 - 자바

📖 문제 📃 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int a = Integer.parseInt(st.nextToken()); int b = ..