#P10996. Counting Valid Quadruplets
Counting Valid Quadruplets
Counting Valid Quadruplets
You are given an integer n
and m
triples \((u_i,v_i,w_i)\) such that \(1 \le u_i < v_i < w_i \le n\) for \(1 \le i \le m\) (all triples are distinct). Your task is to count the number of quadruplets \((a,b,c,d)\) with \(1 \le a < b < c < d \le n\) for which the following four triples exist among the given \(m\) triples:
- \((a,b,c)\)
- \((a,b,d)\)
- \((a,c,d)\)
- \((b,c,d)\)
Formally, you need to count the number of quadruplets \((a,b,c,d)\) satisfying $$1 \le a < b < c < d \le n,$$ such that the set of triples contains all of \((a,b,c)\), \((a,b,d)\), \((a,c,d)\), and \((b,c,d)\).
inputFormat
The first line contains two integers n
and m
, representing the number of nodes and the number of triples, respectively.
Each of the following m
lines contains three integers u
, v
, and w
(with \(1 \le u < v < w \le n\)) that denote a triple.
outputFormat
Output a single integer: the number of quadruplets \((a,b,c,d)\) that meet the condition.
sample
4 4
1 2 3
1 2 4
1 3 4
2 3 4
1