import sys from collections import defaultdict, deque def main(): N, M = map(int, sys.stdin.readline().split()) edges = defaultdict(list) # Forward edges for BFS/DFS reverse_edges = defaultdict(list) # Reverse edges for probability calculation for _ in range(M): A, B, C = map(int, sys.stdin.readline().split()) edges[A].append(B) reverse_edges[B].append((A, C)) # Determine all nodes reachable from group 0 using BFS reachable = set() queue = deque([0]) reachable.add(0) while queue: u = queue.popleft() for v in edges[u]: if v not in reachable: reachable.add(v) queue.append(v) # Perform topological sort using DFS on reachable nodes visited = set() topo_order = [] def dfs(u): if u in visited or u not in reachable: return visited.add(u) for v in edges[u]: dfs(v) topo_order.append(u) dfs(0) topo_order.reverse() # Reverse to get the correct topological order # Initialize probabilities prob = [0.0] * N prob[0] = 1.0 # Group 0 starts with probability 1.0 # Process each node in topological order for v in topo_order: if v == 0: continue # Skip group 0 as its probability is already set product = 1.0 for (u, c) in reverse_edges[v]: if u in reachable: product *= (1.0 - prob[u] * (c / 100)) prob[v] = 1.0 - product # Output the result with sufficient precision print("{0:.10f}".format(prob[N-1])) if __name__ == "__main__": main()