ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 1219 |
문제명 | 오민식의 고민 |
레벨 | 골드 2 |
분류 |
SPFA |
시간복잡도 | O(VE) |
인풋사이즈 | V<=100, E<=100 |
사용한 언어 | Python |
제출기록 | 35088KB / 172ms |
최고기록 | 64ms |
해결날짜 | 2021/09/23 |
"""Solution code for "BOJ 1219. 오민식의 고민".
- Problem link: https://www.acmicpc.net/problem/1219
- Solution link: http://www.teferi.net/ps/problems/boj/1219
Tags: [SPFA]
"""
import sys
from teflib import tgraph
INF = float('inf')
def main():
N, start, dest, M = [int(x) for x in sys.stdin.readline().split()]
wgraph = [{} for _ in range(N)]
for _ in range(M):
u, v, w = [int(x) for x in sys.stdin.readline().split()]
try:
cost = min(wgraph[u][v], w)
except KeyError:
cost = w
wgraph[u][v] = cost
gain = [int(x) for x in sys.stdin.readline().split()]
for cost_to in wgraph:
for v in cost_to:
cost_to[v] -= gain[v]
cost = tgraph.spfa(wgraph, start)[dest]
if cost == INF:
print('gg')
elif cost == -INF:
print('Gee')
else:
print(gain[start] - cost)
if __name__ == '__main__':
main()