๐Ÿ‘ฉโ€๐ŸŽ“๊ณต๋ถ€ - 2023.12.29 ์˜ค๋Š˜์˜ ๋ฐฑ์ค€ ๋ฌธ์ œํ’€์ด

์œ ๋ น๊ฐœยท2023๋…„ 12์›” 29์ผ
0

PS-์•Œ๊ณ ๋ฆฌ์ฆ˜2

๋ชฉ๋ก ๋ณด๊ธฐ
5/34
post-thumbnail

17836 - ๊ณต์ฃผ๋‹˜์„ ๊ตฌํ•ด๋ผ!

ํ™•์‹คํžˆ ์‹ค๋ฒ„์™€ ๊ณจ๋“œ ์‚ฌ์ด์—๋Š” ๋„˜์„ ์ˆ˜ ์—†๋Š” ์ฐจ์›์˜ ๋ฒฝ์ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ๋ฅผ ํ•œ๋ฒˆ ๋” ๊ผฌ์•„๋†จ๋‹ค๊ณ  ํ•ด์•ผ ํ•˜๋‚˜...

(0,0)์— ์šฉ์‚ฌ๊ฐ€ ์žˆ๊ณ  (N,M) ๊ทธ๋Ÿฌ๋‹ˆ๊นŒ ๋์ž๋ฝ์— ๊ณต์ฃผ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์šฉ์‚ฌ๊ฐ€ ๊ณต์ฃผํ•œํ…Œ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ตœ๋‹จ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•ด์„œ ์‹œ๊ฐ„์•ˆ์— ๊ตฌํ–ˆ์œผ๋ฉด ์ตœ๋‹จ๊ฑฐ๋ฆฌ๋ฅผ ์ถœ๋ ฅ, ์‹œ๊ฐ„ ์•ˆ์— ๊ตฌํ•˜์ง€ ๋ชปํ–ˆ๋‹ค๋ฉด Fail์„ ์ถœ๋ ฅํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๋‹จ, ์ด ๋งˆ์™•์„ฑ ์•ˆ์—๋Š” ์ „์„ค์˜ ์„ฑ๊ฒ€ ๊ทธ๋žŒ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋žŒ์„ ํš๋“ํ•  ๊ฒฝ์šฐ ๋ชจ๋“  ๋ฒฝ์„ ๋šซ๊ณ  ๊ฐ€๋Š” ๊ฐœ์น˜ํŠธ ๋ฒฝ๋šซ๊ธฐ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ผ๋‹จ ์ œ๊ฐ€ ๋ฌธ์ œ๋ฅผ ์ฒ˜์Œ ๋ณด๊ณ  ์ƒ๊ฐํ•ด๋‚ธ๊ฑด

1. ๊ฒ€์„ ํš๋“ํ•˜๋Š” ๊ฒฝ์šฐ
2. ๊ฒ€์„ ํš๋“ํ•˜์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ

๋ฅผ ๊ฐ๊ฐ ๋‚˜๋ˆ„์–ด ๊ณ„์‚ฐํ•˜๊ณ  ๋งˆ์ง€๋ง‰์— ํ›„์ฒ˜๋ฆฌ๋กœ ๊ฐ€์žฅ ์งง์€ ์‹œ๊ฐ„ ๋‚ด์— ๊ณต์ฃผ๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’์„ ๋„์ถœํ•˜๋Š”๊ฒŒ ์ œ์ผ ๋ฒ ์ŠคํŠธ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.


๊ธฐ์ดˆ์„ธํŒ…

๋จผ์ € ๊ธฐ๋ณธ์ ์ธ ์„ ์–ธ๊ฐ™์€๊ฑธ ๋ฐ›์•„์˜ต์‹œ๋‹ค.

from collections import deque
import copy
N,M,T = map(int,input().split())
que = deque()
graph = []
for _ in range(N):
    graph.append(list(map(int,input().split())))
graph2 = copy.deepcopy(graph)

๊ทธ๋ž˜ํ”„๋ž‘ ๋งˆ์™•์„ฑ ํฌ๊ธฐ, ๊ณต์ฃผ ๊ตฌํ•˜๋Š” ์‹œ๊ฐ„ ๋“ฑ์„ ๋ฐ›์•„์ฃผ๊ณ  ๊ฒ€์„ ํš๋“ํ•˜๋Š” ๊ฒฝ์šฐ์™€ ๊ฒ€์„ ํš๋“ํ•˜์ง€ ๋ชปํ•œ ์ผ€์ด์Šค๋ฅผ ๋‘˜ ๋‹ค ๊ณ„์‚ฐํ•ด์ฃผ๊ธฐ ์œ„ํ•ด์„œ ๊นŠ์€ ๋ณต์‚ฌ deepcopy๋ฅผ ํ•˜์—ฌ graph์™€ ๋˜‘๊ฐ™์€ graph2๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์ฃผ๊ฒ ์Šต๋‹ˆ๋‹ค.

๋˜ํ•œ ์–ธ์ œ๋‚˜ BFS ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ que๋ฅผ ๋ถˆ๋Ÿฌ์™€์ฃผ๊ณ 

yes_gram = abs(bfs_yesgram(0,0))
no_gram = abs(bfs_nogram(0,0))

์ „์„ค์˜ ์„ฑ๊ฒ€ ๊ทธ๋žŒ์„ ํš๋“ํ•œ ๊ฒฝ์šฐ๋ฅผ yes_gram, ๊ทธ๋žŒ์„ ํš๋“ํ•˜์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ๋ฅผ no_gram์œผ๋กœ ๊ฐ๊ฐ ๋‚˜๋ˆ„์–ด ๋ณ€์ˆ˜๋กœ์จ ๋‹ด์•„์ฃผ๊ฒ ์Šต๋‹ˆ๋‹ค.


๊ฒ€์„ ํš๋“ํ•˜์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ

์ž ๋จผ์ € ๋” ๊ฐ„๋‹จํžˆ ๊ณ„์‚ฐ๊ฐ€๋Šฅํ•œ ๊ฒ€์„ ํš๋“ํ•˜์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ๋ฅผ ์‚ดํŽด๋ด…์‹œ๋‹ค.

ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋ฅผ ์‚ดํŽด๋ณด๋ฉด ๋ฒฝ์€ 1, ์ „์„ค์˜ ์„ฑ๊ฒ€ ๊ทธ๋žŒ์€ 2๋กœ ํ‘œ๊ธฐ๊ฐ€ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
๋งŒ์•ฝ BFS๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ ๊ฐ ์ž๋ฆฌ ๋ฐฉ๋ฌธ์ˆ˜๋ฅผ ๋‹จ์ˆœํžˆ +1์”ฉ ์ฆ์ง„์‹œํ‚จ๋‹ค๋ฉด ๊ณ„์‚ฐํ•˜๋Š” ๋„์ค‘ ์ € ๋ฒฝ๊ณผ ๊ทธ๋žŒ์˜ ์ถฉ๋Œ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ ์ €๋Š” ์Œ์ˆ˜๋กœ ๊ฐ ์ž๋ฆฌ์— ์ตœ๋‹จ๊ฑฐ๋ฆฌ๋ฅผ ํ‘œ๊ธฐํ•ด์ฃผ๊ฒ ์Šต๋‹ˆ๋‹ค.

dx = [0,0,-1,1]
dy = [1,-1,0,0]

def bfs_nogram(x,y):
    que.append([x,y])
    while que:
        x,y = que.popleft()
        for i in range(4):
            nx = dx[i] + x
            ny = dy[i] + y

            if nx<0 or ny<0 or nx>=N or ny>=M:
                continue 

์ƒํ•˜์ขŒ์šฐ ํƒ์ƒ‰ ๊ธฐ์ค€ dx์™€ dy๋ฅผ ์„ ์–ธํ•ด์ฃผ๊ณ  x๋ž‘ y, ๊ทธ๋Ÿฌ๋‹ˆ๊นŒ ์‹œ์ž‘์  0,0 ๋ถ€ํ„ฐ ๋ฐ›์•„ 4๋ฐฉํ–ฅ ํƒ์ƒ‰์„ ์ญ‰ ์ง„ํ–‰ํ•ด์ค์‹œ๋‹ค.

            if graph[nx][ny] == 0:
                graph[nx][ny] = graph[x][y] - 1
                que.append([nx,ny])
    return graph[N-1][M-1]

0์€ ๋ฒฝ๋„ ์•„๋‹ˆ๊ณ  ์„ฑ๊ฒ€ ๊ทธ๋žŒ๋„ ์•„๋‹Œ ๋‹ค์Œ ํƒ์ƒ‰์ด ๊ฐ€๋Šฅํ•œ ์ธ๋ฑ์Šค์ด๋ฏ€๋กœ ๋งŒ๋‚  ๊ฒฝ์šฐ์—” ์ „ ์ธ๋ฑ์Šค -1๋กœ ํ‘œ๊ธฐํ•ด์ค์‹œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ํƒ์ƒ‰์ด ๋‹ค ๋๋‚œ๋‹ค๋ฉด ๋ฆฌ์ŠคํŠธ๋Š” 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋ฏ€๋กœ graph[N-1][M-1]์„ ๋ฆฌํ„ดํ•ด์ฃผ๋ฉด ๊ฒ€์„ ํš๋“ํ•˜์ง€ ์•Š๊ณ  ๊ณต์ฃผ๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ๋‹จ๊ฑฐ๋ฆฌ๊ฐ€ ๋‚˜์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์œ„ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋Œ€๋กœ ์‹คํ–‰์‹œ์ผœ๋ดค์„ ๋•Œ ๋‚˜์˜ค๋Š” ์ถœ๋ ฅ๊ฐ’. ์ด์ „ ๊ฒŒ์‹œ๊ธ€์—๋„ ์žˆ์ง€๋งŒ 0,0์€ 1,0 ๋˜๋Š” 0,1์˜ ํƒ์ƒ‰์— ์žฌ ์˜ํ–ฅ์„ ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์œ ํšจํ•œ ์ถœ๋ ฅ๊ฐ’์ด ์•„๋‹™๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋ฌธ์ œ์˜ ๋ชฉํ‘œ๋Š” graph[N-1][M-1]์˜ ๊ณต์ฃผ๋ฅผ ๊ตฌํ•˜๋Š” ์ตœ๋‹จ๊ฑฐ๋ฆฌ์ด๋ฏ€๋กœ ํฌ๊ฒŒ ์œ ์˜๋ฏธํ•œ ๊ฐ’์€ ์•„๋‹™๋‹ˆ๋‹ค.


๊ฒ€์„ ํš๋“ํ•œ ๊ฒฝ์šฐ

๊ฒ€์„ ํš๋“ํ•œ ๊ฒฝ์šฐ๋Š” ๋‘๋ฒˆ ๋‚˜๋‰˜์–ด์„œ ์ƒ๊ฐํ•ด๋ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

1. ๊ฒ€๊นŒ์ง€ ๊ฐ€๋Š” ์ตœ๋‹จ๊ฑฐ๋ฆฌ
2. ํ•ด๋‹น ๊ฒ€์—์„œ ์ข…๋ฃŒ์ง€์  graph[N-1][M-1]๊นŒ์ง€ ๊ฐ€๋Š” ์ตœ๋‹จ๊ฑฐ๋ฆฌ

๊ทธ๋Ÿฌ๋‹ˆ๊นŒ ๋”ฐ์ง€๊ณ ๋ณด๋ฉด ์‹œ์ž‘์ ->๊ฒ€ ๊ตฌํ•˜๊ณ  ๊ฒ€->์ข…๋ฃŒ์ง€์  ๊ตฌํ•ด์„œ ๋‘˜์ด ๋”ํ•˜๋ฉด ๋œ๋‹ค๋Š” ์†Œ๋ฆฌ์ž…๋‹ˆ๋‹ค.
๊ตณ์ด ์•ˆ๋”ํ•˜๊ณ  ๊ฒ€์— ์ตœ๋‹จ๊ฑฐ๋ฆฌ ๊ธฐ๋กํ•ด๋†“๊ณ  ๋‹ค์‹œ BFS ๋Œ๋ ค๋‘ ๋˜๊ตฌ์š”.

def bfs_yesgram(x,y):
    que.append([x,y])
    while que:
        x,y = que.popleft()
        for i in range(4):
            nx = dx[i] + x
            ny = dy[i] + y

            if nx<0 or ny<0 or nx>=N or ny>=M:
                continue 
            if graph2[nx][ny] == 0:
                graph2[nx][ny] = graph2[x][y] - 1
                que.append([nx,ny])`

๋จผ์ € ์ดˆ๋ฐ˜๋ถ€๋Š” ์•ž์˜ BFS ์ฝ”๋“œ์™€ ์ผ์น˜ํ•ฉ๋‹ˆ๋‹ค. ์ผ๋‹จ ๊ฒ€๊นŒ์ง€ ๊ฐ€๋Š” ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•ด์•ผ ํ•˜๋‹ˆ๊นŒ์š”.

            if graph2[nx][ny] == 2:
                graph2[nx][ny] = graph2[x][y] - 1
                for n in range(N):
                    for m in range(M):
                        if n != nx or m != ny:
                            graph2[n][m] = 0
                que.clear()
                que.append([nx,ny])
                break

๋ถ„๊ธฐ์ ์€ ์—ฌ๊ธฐ์„œ ์ƒ๊น๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ „์„ค์˜ ์„ฑ๊ฒ€(2) ๊ทธ๋žŒ์„ ๋งŒ๋‚ฌ๋‹ค๋ฉด ์ผ๋‹จ ๊ฒ€์ด ์žˆ๋Š” ํ•ด๋‹น ์ธ๋ฑ์Šค์— ๊ฑฐ๊ธฐ๊นŒ์ง€ ๊ฐ€๋Š” ์ตœ๋‹จ๊ฑฐ๋ฆฌ๋ฅผ ๊ธฐ๋กํ•ด์ค๋‹ˆ๋‹ค.

์ƒ๋‹จ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋Œ€๋กœ๋ผ๋ฉด ์ด๋Ÿฐ ์ถœ๋ ฅ์ด๊ฒ ์ง€์š”?
์ € -6์ž๋ฆฌ๊ฐ€ ์„ฑ๊ฒ€ ๊ทธ๋žŒ์„ ์–ป๋Š” ์ตœ๋‹จ ๊ฑฐ๋ฆฌ์ธ ๊ฒ๋‹ˆ๋‹ค.
์ด๋ ‡๊ฒŒ ๊ทธ๋žŒ์„ ์–ป์—ˆ๋‹ค๋ฉด ์ €ํฌ๋Š” ํฌ๋Œ€์˜ ๊ฐœ์‚ฌ๊ธฐ ์น˜ํŠธ ๋ฒฝ๋šซ๊ธฐ๋ฅผ ์‹œ์ „ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด์ „์— ์ตœ๋‹จ๊ฑฐ๋ฆฌ ๊ธฐ๋กํ•ด๋‘” ๊ฒƒ๋“ค๊ณผ ๋ฒฝ์„ ์‹น๋‹ค ๋‚ ๋ ค๋ฒ„๋ฆฝ์‹œ๋‹ค. (ํ ์ดˆ๊ธฐํ™”, ํ์— ๊ฒ€์œ„์น˜(ํ˜„์žฌ์ง€์ ) ๋„ฃ์–ด์„œ ํƒ์ƒ‰ ์œ ๋„)

ํ•œ์ธต ๊น”๋”ํ•ด์กŒ๋„ค์š”.
์ด์ œ BFS๋ฅผ ๋‹ค์‹œ ๋Œ๋ ค ๊ฒ€->์ข…๋ฃŒ์ง€์  graph[N-1][M-1] ๊นŒ์ง€์˜ ์ตœ๋‹จ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.


์—ฌ๊ธฐ์„  ๊ฒ€์—์„œ ์ข…๋ฃŒ์ง€์ ๊นŒ์ง€ ์ตœ๋‹จ๊ฑฐ๋ฆฌ๋Š” 4์ด๋ฉฐ ์ตœ์ข…์ ์œผ๋กœ ๊ณต์ฃผ๋ฅผ ๊ตฌํ•˜๋Š” ์ตœ๋‹จ๊ฑฐ๋ฆฌ๋Š” 10์ด๊ฒ ๋„ค์š”.


์ถœ๋ ฅ

์—ญ์‹œ ๊ณจ๋“œ๋ฌธ์ œ๋Š” ํ—ˆ์ ‘ ์‹ค๋ฒ„๋ฌธ์ œ์™€๋Š” ์ฐจ์›์ด ๋‹ค๋ฅด๊ฒŒ ์ถœ๋ ฅ์กฐ์ฐจ ๋ณต์žกํ•ฉ๋‹ˆ๋‹ค.
๊ธฐ์–ตํ•˜์‹ค์ง€ ๋ชจ๋ฅด์‹œ๊ฒ ์ง€๋งŒ ์ €ํฌ๊ฐ€ ์ฒ˜์Œ์— T๋ผ๋Š” ๋ณ€์ˆ˜๋ฅผ ๋ฐ›์•˜์ฃ ? ์ด ์‹œ๊ฐ„ ์•ˆ์— ๊ณต์ฃผ๋ฅผ ๋ชป๊ตฌํ•˜๋ฉด ๋ฌด์กฐ๊ฑด Fail์„ ์ถœ๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์ƒ๋‹จ์— ๋ณด์‹œ๋Š” ํ…Œ์ŠคํŠธ์ผ€์ด์Šค์ฒ˜๋Ÿผ ๋ฒฝ์ด ์•„์˜ˆ ๋ง‰ํ˜€ ๊ตฌํ•˜๋Ÿฌ ๊ฐ€์ง€ ๋ชปํ•  ๊ฒฝ์šฐ๋„ ๊ณ ๋ คํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

if yes_gram == 0 or no_gram == 0:
    if yes_gram == 0 and no_gram != 0:
        if no_gram <= T:
            print(no_gram)
        else:
            print('Fail')
    elif yes_gram != 0 and no_gram == 0:
        if yes_gram <= T:
            print(yes_gram)
        else:
            print('Fail')
    else:
        print('Fail')

์ผ๋‹จ ๋‘˜ ์ค‘์— ํ•˜๋‚˜๋ผ๋„ 0์ด ์žˆ๋‹ค๋ฉด์„ if๋ฌธ์œผ๋กœ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค.
๋‘˜๋‹ค 0์ด๋ผ๋ฉด ๋ฒฝ์— ๋ง‰ํ˜€ ์•„์‰ฝ๊ฒŒ๋„ ๊ณต์ฃผ๋ฅผ ๊ตฌํ•˜๋Ÿฌ ๊ฐ€์ง€ ๋ชปํ•˜๋ฏ€๋กœ Fail์„ ์ถœ๋ ฅํ•ด์ค๋‹ˆ๋‹ค.

๋งŒ์•ฝ ํ•˜๋‚˜๋งŒ 0์ด๋ผ๋ฉด ๋‚˜๋จธ์ง€ 0์ด ์•„๋‹Œ ๊ฐ’์„ T์™€ ๋Œ€์กฐํ•ด๋ณด๊ณ  T์ดˆ ์ดํ•˜๋กœ ๊ตฌํ•˜๋Š”๊ฒŒ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ํ•ด๋‹น ๊ฐ’์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
๋งˆ์ฐฌ๊ฐ€์ง€๋กœ T์ดˆ ์ดˆ๊ณผ๋ฉด Fail์„ ์ถœ๋ ฅํ•ด์ค๋‹ˆ๋‹ค.

else:
    if min(yes_gram,no_gram) > T:
        print('Fail')
    else:
        print(min(yes_gram,no_gram))

๋งŒ์•ฝ ๋‘˜๋‹ค ๊ฐ’์ด 0์ด ์•„๋‹ˆ๋ผ๋ฉด ๋” ์ž‘์€ ๊ฐ’๊ณผ T๋ฅผ ๋Œ€์กฐํ•ด์„œ T์ดˆ ์ดํ•˜๋กœ ๊ตฌํ•˜๋Š” ๊ฒŒ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ํ•ด๋‹น ๊ฐ’์„, ์•„๋‹ˆ๋ฉด Fail์„ ์ถœ๋ ฅํ•˜๋ฉด ๋๋‚ฉ๋‹ˆ๋‹ค.


์ „์ฒด ์ฝ”๋“œ

from collections import deque
import copy
dx = [0,0,-1,1]
dy = [1,-1,0,0]

def bfs_yesgram(x,y):
    que.append([x,y])
    while que:
        x,y = que.popleft()
        for i in range(4):
            nx = dx[i] + x
            ny = dy[i] + y

            if nx<0 or ny<0 or nx>=N or ny>=M:
                continue 
            if graph2[nx][ny] == 0:
                graph2[nx][ny] = graph2[x][y] - 1
                que.append([nx,ny])
            if graph2[nx][ny] == 2:
                graph2[nx][ny] = graph2[x][y] - 1

                for n in range(N):
                    for m in range(M):
                        if n != nx or m != ny:
                            graph2[n][m] = 0
                que.clear()
                que.append([nx,ny])
                break

    return graph2[N-1][M-1]

def bfs_nogram(x,y):
    que.append([x,y])
    while que:
        x,y = que.popleft()
        for i in range(4):
            nx = dx[i] + x
            ny = dy[i] + y

            if nx<0 or ny<0 or nx>=N or ny>=M:
                continue 
            if graph[nx][ny] == 0:
                graph[nx][ny] = graph[x][y] - 1
                que.append([nx,ny])
    return graph[N-1][M-1]


N,M,T = map(int,input().split())
que = deque()
graph = []
for _ in range(N):
    graph.append(list(map(int,input().split())))
graph2 = copy.deepcopy(graph)

yes_gram = abs(bfs_yesgram(0,0))
no_gram = abs(bfs_nogram(0,0))


if yes_gram == 0 or no_gram == 0:
    if yes_gram == 0 and no_gram != 0:
        if no_gram <= T:
            print(no_gram)
        else:
            print('Fail')
    elif yes_gram != 0 and no_gram == 0:
        if yes_gram <= T:
            print(yes_gram)
        else:
            print('Fail')
    else:
        print('Fail')
else:
    if min(yes_gram,no_gram) > T:
        print('Fail')
    else:
        print(min(yes_gram,no_gram))



profile
ํ•œ๋ฆผ๋Œ€ํ•™๊ต ์ •๋ณด๊ณผํ•™๋Œ€ 2ํ•™๋…„ ์žฌํ•™์ค‘ / ์œก๊ตฐ ์ •๋ณด๋ณดํ˜ธ๋ณ‘ 22-2๊ธฐ

0๊ฐœ์˜ ๋Œ“๊ธ€