結果
問題 | No.298 話の伝達 |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:19:54 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,341 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 56,108 KB |
最終ジャッジ日時 | 2025-03-20 21:20:53 |
合計ジャッジ時間 | 1,797 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 WA * 11 |
ソースコード
import sysfrom collections import dequedef main():N, M = map(int, sys.stdin.readline().split())adj = [[] for _ in range(N)]edges = [[] for _ in range(N)]for _ in range(M):A, B, C = map(int, sys.stdin.readline().split())if B != 0: # Ignore edges pointing to group 0adj[A].append(B)edges[B].append((A, C))# Calculate in_degree for each node (number of incoming edges excluding those to 0)in_degree = [0] * Nfor b in range(N):in_degree[b] = len(edges[b])# Perform topological sortqueue = deque()order = []for i in range(N):if in_degree[i] == 0:queue.append(i)while queue:u = queue.popleft()order.append(u)for v in adj[u]:in_degree[v] -= 1if in_degree[v] == 0:queue.append(v)# Initialize probabilitiesP = [0.0] * NP[0] = 1.0 # Group 0 starts the topic# Compute probabilities in topological orderfor u in order:if u == 0:continue # already set to 1.0product = 1.0for (A, C) in edges[u]:product *= (1.0 - P[A] * (C / 100.0))P[u] = 1.0 - productprint("{0:.10f}".format(P[N-1]))if __name__ == "__main__":main()