eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Triangles

Triangles

\textbf{N} nails are hammered in the wall. Some pairs of nails are connected with wires, possibly multiple. You may assume that there are no wires connecting nail to itself. Each wire is colored: white, blue, or red. We say that three wires form a triangle if there is a cycle connecting three nails. We call a triangle multi-colored if it is formed by wires of three distinct colors. Write a program to compute the number of multi-colored triangles for a given list of wires. \InputFile The first line of the input file contains two space-delimited numbers \textbf{N} and \textbf{M} (\textbf{2} ≤ \textbf{N} ≤ \textbf{1000}, \textbf{0} ≤ \textbf{M} ≤ \textbf{3000}) --- the number of nails and the number of wires. Each of the following \textbf{M} lines contains three integers: numbers of nails being connected by a wire, and the color of that wire. The color is indicated by integers \textbf{1}, \textbf{2}, or \textbf{3}. \OutputFile The output file should contain a single integer, the number of multi-colored triangles. \textbf{Example explanation} The multi-colored triangles are formed by the following triples of wires: \begin{itemize} \item (1,3,1), (3,4,2), (1,4,3); \item (1,3,1), (3,4,2), (1,4,3); \item (1,3,2), (4,3,1), (1,4,3); \item (1,3,2), (4,3,1), (1,4,3). \end{itemize} \textbf{Please note}. In the example, the first and the second triangles, as well as the third and the fourth ones seem to be identical, however, given that there are two wires of the same color between the nails \textbf{#1} and \textbf{#4}, the triangles are considered to be different as different wires are used to form the triangles.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
4 8
1 2 1
1 3 1
2 3 1
1 3 2
1 4 3
1 4 3
4 3 1
3 4 2
Вихідні дані #1
4
Джерело 2013-2014 ACM Central Region of Russia Quarterfinal, Rybinsk 2013/10/17