#C574. Find the Highest Reachable Probability in a Forest
Find the Highest Reachable Probability in a Forest
Find the Highest Reachable Probability in a Forest
You are given a directed forest with n regions (nodes) and m directed paths (edges). Each region has an associated probability score. Starting from a specified region, your task is to determine the highest probability score among all regions that are reachable using the directed paths.
To solve the problem, perform a Breadth-First Search (BFS) starting from the given region. During the traversal, keep track of the maximum probability encountered. Note that the starting region's probability must be considered as well.
Note: Regions are numbered from 0 to n-1 and the graph might be disconnected. Input ends when a dataset with n = m = start = 0 is encountered, which should not be processed.
inputFormat
The input consists of multiple datasets. Each dataset is described as follows:
- The first line contains three integers n, m, and start, where n is the number of regions, m is the number of edges, and start is the starting region (0-indexed).
- The second line contains n integers representing the probability scores of the regions.
- The following m lines each contain two integers u and v, indicating a directed edge from region u to region v.
The input terminates with a line containing 0 0 0
, which should not be processed.
outputFormat
For each dataset, output a single line containing the highest probability score among all regions that are reachable from the starting region.
## sample5 6 0
10 50 30 20 40
0 1
0 2
1 3
1 4
2 4
3 4
0 0 0
50
</p>