728x90
๋ฐ˜์‘ํ˜•

๊ทธ๋ž˜ํ”„ํƒ์ƒ‰ 3

[๋ฐฑ์ค€ 1012] [dfs/bfs] ์œ ๊ธฐ๋† ๋ฐฐ์ถ”

๐Ÿ’ป ๋ฐฑ์ค€ 1012๋ฒˆ [์œ ๊ธฐ๋† ๋ฐฐ์ถ”] 1012๋ฒˆ: ์œ ๊ธฐ๋† ๋ฐฐ์ถ” ์ฐจ์„ธ๋Œ€ ์˜๋†์ธ ํ•œ๋‚˜๋Š” ๊ฐ•์›๋„ ๊ณ ๋žญ์ง€์—์„œ ์œ ๊ธฐ๋† ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค. ๋†์•ฝ์„ ์“ฐ์ง€ ์•Š๊ณ  ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๋ ค๋ฉด ๋ฐฐ์ถ”๋ฅผ ํ•ด์ถฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ•œ๋‚˜๋Š” ํ•ด์ถฉ ๋ฐฉ์ง€์— www.acmicpc.net ํ’€์ด) import sys sys.setrecursionlimit(100000000) T = int(input()) cnt_lst = [] for t in range(T) : m,n,k = map(int,input().split()) cab = [list(map(int,input().split())) for _ in range(k)] map_ = [[0]*m for _ in range(n)] for i,j in cab : map_[j][i..

[๋ฐฑ์ค€ 1012] [dfs/bfs] ์œ ๊ธฐ๋† ๋ฐฐ์ถ”

๐Ÿ’ป ๋ฐฑ์ค€ 1012๋ฒˆ [์œ ๊ธฐ๋† ๋ฐฐ์ถ”] 1012๋ฒˆ: ์œ ๊ธฐ๋† ๋ฐฐ์ถ” ์ฐจ์„ธ๋Œ€ ์˜๋†์ธ ํ•œ๋‚˜๋Š” ๊ฐ•์›๋„ ๊ณ ๋žญ์ง€์—์„œ ์œ ๊ธฐ๋† ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค. ๋†์•ฝ์„ ์“ฐ์ง€ ์•Š๊ณ  ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๋ ค๋ฉด ๋ฐฐ์ถ”๋ฅผ ํ•ด์ถฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ•œ๋‚˜๋Š” ํ•ด์ถฉ ๋ฐฉ์ง€์— www.acmicpc.net ํ’€์ด) import sys sys.setrecursionlimit(100000000) T = int(input()) cnt_lst = [] for t in range(T) : m,n,k = map(int,input().split()) cab = [list(map(int,input().split())) for _ in range(k)] map_ = [[0]*m for _ in range(n)] for i,j in cab : map_[j][i..

[๋ฐฑ์ค€ 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..

728x90
๋ฐ˜์‘ํ˜•