Problem B
Pachinko Probability

A pachinko machine is a Japanese invention that is sort of like a pinball machine. Each pachinko machine uses marbles which fall from the top and bounce off of fixed pins until they reach the bottom. When they reach the bottom, if they fall into a particular area (a ‘gate’), then that round wins; otherwise, the round loses.
![\includegraphics[width=0.2\textwidth ]{example_1}](/problems/pachinkoprobability/file/statement/en/img-0002.png)
![\includegraphics[width=0.2\textwidth ]{example_2}](/problems/pachinkoprobability/file/statement/en/img-0003.png)
In Figure 1, which illustrates the sample inputs, the nodes represent possible marble locations (nodes are not the pins; they are between the pins), the boxes represent gates, and the edges represent possible transitions between locations. Write a program to find out how likely it is that you can win at pachinko.
Input
Input contains a description of a single machine, which is
given as a directed acyclic graph indicating the places a
marble can travel as it proceeds from the top to the bottom. A
marble may start at any graph node that has no incoming edges,
and always ends at a node having no outgoing edges. Each
machine starts with a line containing an integer
Output
Print out the number of possible winning paths (those ending in a gate) and the total number of possible paths. Do not reduce these numbers. A ‘possible path’ is any sequence of graph nodes that lead from a starting node to an ending node.
Sample Input 1 | Sample Output 1 |
---|---|
3 2 0 1 0 2 1 1 |
winning paths 1 total paths 2 |
Sample Input 2 | Sample Output 2 |
---|---|
6 8 0 2 0 3 1 2 1 3 2 4 2 5 3 4 3 5 1 4 |
winning paths 4 total paths 8 |