728x90
๋ฐ˜์‘ํ˜•

๋ฐฑ์ค€ 4

[๋ฐฑ์ค€ 1260] [dfs/bfs] BFS์™€ DFS โ—

๐Ÿ’ป ๋ฐฑ์ค€ 1260๋ฒˆ [BFS์™€ DFS]1260๋ฒˆ: DFS์™€ BFS์ฒซ์งธ ์ค„์— ์ •์ ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 1,000), ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜ M(1 ≤ M ≤ 10,000), ํƒ์ƒ‰์„ ์‹œ์ž‘ํ•  ์ •์ ์˜ ๋ฒˆํ˜ธ V๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ M๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ„์„ ์ด ์—ฐ๊ฒฐํ•˜๋Š” ๋‘ ์ •์ ์˜ ๋ฒˆํ˜ธ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์–ด๋–ค ๋‘ ์ •์  ์‚ฌwww.acmicpc.netํ’€์ด)# ์ตœ์ข…์ œ์ถœ from collections import deque n,m,v = map(int,input().split()) input_lst = sorted([list(map(int,input().split())) for _ in range(m)], key = lambda x : (x[0],x[1])) edge_lst = [[] for _ in range(n+1)] for v1,v2 i..

[๋ฐฑ์ค€ 2331] [dfs] ๋ฐ˜๋ณต์ˆ˜์—ด

๐Ÿ’ป ๋ฐฑ์ค€ 2331๋ฒˆ [๋ฐ˜๋ณต์ˆ˜์—ด] 2331๋ฒˆ: ๋ฐ˜๋ณต์ˆ˜์—ด ์ฒซ์งธ ์ค„์— ๋ฐ˜๋ณต๋˜๋Š” ๋ถ€๋ถ„์„ ์ œ์™ธํ–ˆ์„ ๋•Œ, ์ˆ˜์—ด์— ๋‚จ๊ฒŒ ๋˜๋Š” ์ˆ˜๋“ค์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. www.acmicpc.net ํ’€์ด) ์ฒซ๋ฒˆ์งธ ์ œ์ถœ : ๋Ÿฐํƒ€์ž„์—๋Ÿฌ(ModuleNotFoundError) ๋œธ ์•Œ๊ณ ๋ณด๋‹ˆ ๋ฐฑ์ค€์—์„œ๋Š” numpy๋ฅผ ๋ชป ์“ฐ๊ฒŒ ํ•จ...;;^^ # ์ฒซ๋ฒˆ์งธ import numpy as np a,p = map(int,input().split()) visited = {} stack = [] def cal(a,p) : if a in visited : return stack.pop() else : visited[a] = 1 stack.append(a) return cal(np.sum([int(i)**p for i in str(a)]),p) dup_n = cal..

728x90
๋ฐ˜์‘ํ˜•