Squares in a graph

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

Input

Input consists of several cases. Every case begins with two natural
numbers n and m, which are respectively the number of vertices and the
number of edges of G. Follow m pairs x y to indicate that there is an
edge connecting vertices x and y. Assume 0 ≤ n ≤ 2000 and 0 ≤ m ≤ 10n.
Vertices are numbered starting at 0. There are no edges of the kind x x,
nor repeated edges.

Output

For every given G, print its number of squares.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T12:23:07.685Z

© Jutge.org, 2006–2026.
https://jutge.org
