Squares in a graph P99912


Statement
 

pdf   zip

You are given an undirected graph GG. Let us define a square as any cycle of length exactly four in GG. Can you count the number of squares in GG?

Input

Input consists of several cases. Every case begins with two natural numbers nn and mm, which are respectively the number of vertices and the number of edges of GG. Follow mm pairs xx yy to indicate that there is an edge connecting vertices xx and yy. Assume 0n20000 \le n \le 2000 and 0m10n0 \le m \le 10n. Vertices are numbered starting at 0. There are no edges of the kind xx xx, nor repeated edges.

Output

For every given GG, print its number of squares.

Public test cases
  • Input

    4 4
    0 1  1 2  2 3  3 0
    
    6 5
    0 1  0 2  1 2  2 4  4 5
    
    5 7
    0 1  2 0  0 3  4 1  2 4  3 4  2 1
    

    Output

    1
    0
    3
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++