This page is still under construction.

Parts of this page are still being built. What you see may change.

Street Network

Time limit1sMemory limit128 MB

Summary
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.

  1. 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.)
  2. How many nodes can serve as the starting point of such a route?
  3. For each node XX, how many routes of length SS start at XX and return to XX? (A street or node may be used more than once.)

Input

The first line contains a positive integer NN (N≤50N \le 50), the number of nodes.

The second line contains a positive integer SS (S≤3S \le 3), the path length.

The next NN lines describe the network as a matrix. The value in row II, column JJ is the number of streets going from node II to node JJ. Nodes are numbered from 11 to NN.

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 SS that leave the node and return to it, then print these NN values sorted in increasing order, separated by single spaces.

When the answer is NO, print only NO on the first line.

Examples4

  1. Example 1

    Input
    3
    2
    1 1 0
    1 1 1
    0 1 1
    
    Expected output
    YES
    3
    2 2 3
    
  2. Example 2

    Input
    1
    1
    1
    
    Expected output
    YES
    1
    1
    
  3. Example 3

    Input
    3
    1
    0 1 0
    0 0 1
    0 0 0
    
    Expected output
    YES
    1
    0 0 0
    
  4. Example 4

    Input
    2
    1
    0 2
    0 0
    
    Expected output
    NO