G - Triangle Editorial by orzzhouAK


We can know that we need to count the number of loops in the graph which only contains three vertices .

When considering each edge \((u,v)\) in the graph, we are going to find the number of vertex \(w\) that makes edges \((u,w)\) and \((v,w)\) both exist.

If we count the number of \(w\) using brute force, we need the complexity of \(O(nm)\), which \(m\) is the number of edges in the graph. And it obviously cannot pass this problem.

And now we can optimize it by using bitset to make it \(O(\dfrac{nm}{w})\) which \(w=64\).

Here is the Submission.

posted:
last update: