from collections import deque def main(): n, m = map(int, input().split()) adj = [[] for _ in range(n)] # adjacency list for forward edges in_edges = [[] for _ in range(n)] # list of incoming edges (A, C) for each node B for _ in range(m): a, b, c = map(int, input().split()) adj[a].append(b) in_edges[b].append((a, c)) # Find reachable nodes from group 0 using BFS def get_reachable(start): visited = [False] * n q = deque([start]) visited[start] = True while q: u = q.popleft() for v in adj[u]: if not visited[v]: visited[v] = True q.append(v) return [i for i in range(n) if visited[i]] reachable = get_reachable(0) if (n-1) not in reachable: print(0.0) return # Perform topological sort on the reachable nodes def topological_sort(nodes): visited = {node: False for node in nodes} order = [] def dfs(u): if visited[u]: return visited[u] = True for v in adj[u]: if v in visited and not visited[v]: dfs(v) order.append(u) for node in nodes: if not visited[node]: dfs(node) return order[::-1] topo_order = topological_sort(reachable) # Calculate probabilities prob = [0.0] * n prob[0] = 1.0 # initial group for u in topo_order: if u == 0: continue product = 1.0 for (a, c) in in_edges[u]: if a < 0 or a >= n: continue # should not happen as per input constraints product *= (1.0 - prob[a] * (c / 100.0)) prob[u] = 1.0 - product print("{0:.10f}".format(prob[n-1])) if __name__ == "__main__": main()