Baekjoon 10675번 [Cow Routing]

https://www.acmicpc.net/problem/10675

 

10675번: Cow Routing

Tired of the cold winter weather on her farm, Bessie the cow plans to fly to a warmer destination for vacation.  Unfortunately, she discovers that only one airline, Air Bovinia, is willing to sell tickets to cows, and that these tickets are somewhat compl

www.acmicpc.net

 

  • 사용언어: Python (PyPy3)
  • 알고리즘: 구현

 


 

문제

 

 


 

코드

 

처음에는 여러 비행기를 타도 되는 줄 알고 왜 이게 브론즈 문제일까 고민했다..

 

A, B, N = map(int, input().split())
ans = 1001
for i in range(N):
    cost, num = map(int, input().split())
    ListOfCities = list(map(int, input().split()))
    Departures = False
    for city in ListOfCities:
        if A == city: # 출발지에 도착한 경우
            Departures = True 
        elif B == city: # 도착지에 도착한 경우
            if not Departures: # 출발지를 아직 거쳐오지 않은 경우
                break
            else: # 출발지를 거쳐온 경우
                if cost < ans:
                    ans = cost
if ans != 1001:
    print(ans)
else:
    print(-1)

 

 

'백준 > USACO bronze 기출' 카테고리의 다른 글

[백준] 14530번 The Lost Cow  (0) 2022.10.03
[백준] 14175번 The Cow-Signal  (0) 2022.10.03
[백준] 15751번 Teleportation  (0) 2022.10.03
[백준] 11970번 Fence Painting  (0) 2022.10.03
[백준] 14173번 Square Pasture  (0) 2022.10.02

+ Recent posts