結果
| 問題 |
No.298 話の伝達
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:40:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,133 bytes |
| コンパイル時間 | 175 ms |
| コンパイル使用メモリ | 82,744 KB |
| 実行使用メモリ | 56,028 KB |
| 最終ジャッジ日時 | 2025-06-12 16:40:39 |
| 合計ジャッジ時間 | 1,882 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 11 |
ソースコード
import sys
from collections import deque
def main():
n, m = map(int, sys.stdin.readline().split())
edges = [[] for _ in range(n)] # edges[b] contains (a, c)
adj = [[] for _ in range(n)] # adj[a] contains b
in_degree = [0] * n
for _ in range(m):
a, b, c = map(int, sys.stdin.readline().split())
edges[b].append((a, c))
adj[a].append(b)
in_degree[b] += 1
# Topological sort using Kahn's algorithm
queue = deque()
for i in range(n):
if in_degree[i] == 0:
queue.append(i)
top_order = []
while queue:
u = queue.popleft()
top_order.append(u)
for v in adj[u]:
in_degree[v] -= 1
if in_degree[v] == 0:
queue.append(v)
p = [0.0] * n
p[0] = 1.0 # Group 0 is the starting point
for u in top_order:
if u == 0:
continue
product = 1.0
for (a, c) in edges[u]:
prob = p[a] * (c / 100.0)
product *= (1 - prob)
p[u] = 1 - product
print("{0:.10f}".format(p[n-1]))
if __name__ == "__main__":
main()
gew1fw