Street Network
Time limit1sMemory limit128 MB
Decide whether a directed multigraph has an Eulerian trail, count possible start nodes, and for S at most 3 count closed walks of length S from each node, sorted.
- Level
Medium6 of 10
- Topics
- Graph, Implementation, Math, Matrix
- Solved
- No attempts yet
Problem
The street network of a city consists of streets and nodes. Two or more streets may meet at a node. Every street is one-way. Two nodes may also be connected directly by more than one street, and a node may have a street that loops back to itself (a self-loop).
Write a program that answers the following three questions.
- Does there exist a route that starts at some node and traverses every street exactly once? (It may end back at the starting node or at a different node.)
- How many nodes can serve as the starting point of such a route?
- For each node , how many routes of length start at and return to ? (A street or node may be used more than once.)
Input
The first line contains a positive integer (), the number of nodes.
The second line contains a positive integer (), the path length.
The next lines describe the network as a matrix. The value in row , column is the number of streets going from node to node . Nodes are numbered from to .
Output
On the first line, print the string YES if there exists a route that starts at some node and traverses every street exactly once; otherwise print the string NO.
Only when the answer is YES, print the following two additional lines.
- On the second line, print how many nodes can serve as a starting point of such a route.
- On the third line, for each node compute the number of routes of length that leave the node and return to it, then print these values sorted in increasing order, separated by single spaces.
When the answer is NO, print only NO on the first line.