#C8228. Daisy's Flower Collection
Daisy's Flower Collection
Daisy's Flower Collection
Daisy is on a quest to collect data on the number of flowers in a series of gardens. Each garden contains a unique number of flowers and is connected to other gardens by one-way paths. Starting from a specified garden, Daisy must traverse all reachable gardens without visiting any garden more than once. The challenge is to compute the total number of flowers Daisy collects along her journey.
The gardens and paths form a directed graph, and the traversal can be modeled using either BFS or DFS. Beware of cycles and disconnected components in the graph.
Note: The total count should include the number of flowers in the starting garden as well.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains three integers n, m, and s, where n is the number of gardens, m is the number of directed paths between gardens, and s is the starting garden (1-indexed).
- The second line contains n integers. The i-th integer denotes the number of flowers in the i-th garden.
- The following m lines each contain two integers u and v, representing a one-way path from garden u to garden v.
outputFormat
Output a single integer to standard output (stdout) representing the total number of flowers collected by traversing from the starting garden s along all reachable paths (without revisiting any garden).
## sample4 3 1
10 5 7 3
1 2
2 3
3 4
25