This page is still under construction.

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

Cycle Detection

Time limit1sMemory limit128 MB

Summary
Given a graph on at most 20 vertices, for each edge that lies on a cycle, count how many distinct simple cycles contain it.
Level

Medium7 of 10

Topics
Graph, Brute force, Bit manipulation, DFS
Solved
No attempts yet

Problem

Consider a network of computers in which each computer is connected to others by cables. Every cable connects exactly two computers, and any two computers are joined by at most one cable.

Given such a network, find every cable that belongs to at least one cycle, and for each such cable determine how many cycles it belongs to.

A cycle is a sequence of cables that starts at some computer AA and returns to AA. Every computer other than AA may appear at most once in the cycle. Two cycles made of the same set of cables are counted as one, regardless of direction or starting computer.

Input

The first line contains a positive integer NN (N≤20N \le 20), the number of computers in the network.

Each of the next NN lines describes the connections as an adjacency matrix: every line contains NN values separated by single spaces. If the entry in line LL and column CC is 00, there is no direct connection between computers LL and CC; otherwise the two computers are directly connected.

Output

On the first line, print a positive integer MM, the number of cables that belong to at least one cycle.

On the next line, print MM positive integers separated by single spaces: the number of cycles that each such cable belongs to, sorted in increasing order.

If no cable belongs to any cycle, print a single line containing NO CYCLE.

Examples4

  1. Example 1

    Input
    6
    0 1 1 0 0 0
    1 0 1 1 0 0
    1 1 0 0 0 1
    0 1 0 0 1 0
    0 0 0 1 0 1
    0 0 1 0 1 0
    
    Expected output
    7
    2 2 2 2 2 2 2
    
  2. Example 2

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

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

    Input
    4
    0 1 0 0
    1 0 1 0
    0 1 0 1
    0 0 1 0
    
    Expected output
    NO CYCLE