Skip to content

Latest commit

 

History

History

188-distinct-triangles

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Distinct Triangles

Challenge Description:

Alice the archaeologist has just entered the tomb of the Pharaoh. She turns on her flashlight and notices an undirected graph painted on the wall, with V nodes and E edges. Suddenly, the stone door behind her slams shut. Fortunately, Alice knows the way out - she must place N pebbles upon the altar to re-open the door, where N is the number of triangles in the graph.

For example:

Figure 1

N is 2 in this graph.

Input sample:

The first argument is a file with different test cases. Each test case begins with two integers, V and E (1 <= V, E <= 100), separated by a space and finishes with following symbol ";". Then, E edges, which represented as two integers separated by space, Each edge is comma separated. Each vertex is in the range (0 <= vertex < V).

For example:

4 5;0 2,0 1,1 2,1 3,2 3
9 3;1 3,1 8,3 8
9 3;5 6,5 7,6 7

Output sample:

Print out the number of distinct triangles formed over three vertices and edges in the graph.

For example:

2
1
1

Constraints:

  1. 1 <= V, E <= 100
  2. 0 <= vertex < V
  3. Number of test cases is 10.