ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 5942 |
문제명 | Big Macs Around the World |
레벨 | 플래티넘 5 |
분류 |
SPFA |
시간복잡도 | O(VE) |
인풋사이즈 | V<=2000, E<=25,000 |
사용한 언어 | Python |
제출기록 | 38172KB / 1552ms |
최고기록 | 1552ms |
해결날짜 | 2021/09/24 |
"""Solution code for "BOJ 5942. Big Macs Around the World".
- Problem link: https://www.acmicpc.net/problem/5942
- Solution link: http://www.teferi.net/ps/problems/boj/5942
Tags: [SPFA]
"""
import math
import sys
from teflib import tgraph
INF = float('inf')
def main():
inp = sys.stdin.readline().split()
N, M, A, B = int(inp[0]), int(inp[1]), int(inp[3]), int(inp[4])
V = float(inp[2])
wgraph = [{} for _ in range(N)]
for _ in range(M):
inp = sys.stdin.readline().split()
i, j, e_ij = int(inp[0]), int(inp[1]), float(inp[2])
wgraph[i - 1][j - 1] = math.log(e_ij)
dist = tgraph.spfa(wgraph, A - 1)[B - 1]
print('0' if dist == -INF else V * math.exp(dist))
if __name__ == '__main__':
main()