結果

問題 No.298 話の伝達
ユーザー gew1fw
提出日時 2025-06-12 16:39:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 82,212 KB
実行使用メモリ 56,136 KB
最終ジャッジ日時 2025-06-12 16:39:56
合計ジャッジ時間 2,216 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n, m = map(int, input().split())

adj_in = [[] for _ in range(n)]
in_degree = [0] * n
adj_out = [[] for _ in range(n)]

for _ in range(m):
    a, b, c = map(int, input().split())
    adj_in[b].append((a, c))
    adj_out[a].append(b)
    in_degree[b] += 1

# Compute topological order using Kahn's algorithm
q = deque()
for i in range(n):
    if in_degree[i] == 0:
        q.append(i)

top_order = []

while q:
    u = q.popleft()
    top_order.append(u)
    for v in adj_out[u]:
        in_degree[v] -= 1
        if in_degree[v] == 0:
            q.append(v)

# Compute probabilities
p = [0.0] * n
p[0] = 1.0

for i in top_order:
    if i == 0:
        continue
    product = 1.0
    for (a, c) in adj_in[i]:
        term = 1.0 - p[a] * (c / 100.0)
        product *= term
    p[i] = 1.0 - product

print("{0:.10f}".format(p[n-1]))
0