Diamonds
Time limit2sMemory limit1024 MB
Count the diamonds, which are pairs of triangles sharing an edge, in an undirected graph with up to 300000 vertices and edges.
- Level
Medium6 of 10
- Topics
- Graph, Combinatorics
- Solved
- No attempts yet
Problem
You have learned that an ancient Inca book describes how to defeat Pennywise. You found the book, but unfortunately it is written in the language of graphs.
To understand one page of the book, you need to count the number of diamonds in the graph drawn on that page.
A diamond in an undirected graph without self-loops and multiple edges is two triangles that share a common edge.

Two diamonds are considered different if there is an edge that belongs to one diamond but not to the other.
Input
The first line contains two integers and (), the number of vertices and edges of the graph. Each of the next lines contains two integers and (; ), the vertices joined by the -th edge. It is guaranteed that the graph has no multiple edges.
Output
Print one integer, the number of diamonds in the graph.