목차

Big Macs Around the World

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()