結果
| 問題 |
No.298 話の伝達
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 21:35:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 862 bytes |
| コンパイル時間 | 245 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 54,656 KB |
| 最終ジャッジ日時 | 2025-06-12 21:37:14 |
| 合計ジャッジ時間 | 1,637 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 11 |
ソースコード
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]))
gew1fw