Ancient Magic Circle in Teyvat

시간 제한2초메모리 제한1024 MB

요약
완전 그래프에서 일부 간선만 빨간색으로 주어질 때, 네 정점이 이루는 단색 K4의 빨간색과 파란색 개수 차이의 절댓값을 구한다.
난이도

어려움10점 중 8점

유형
조합론, 수학, 그래프, 완전 탐색
정답자
아직 제출이 없습니다

문제

Astrologist Mona Megistus discovers an ancient magic circle in Teyvat recently.

Pixiv ID: 89228733

The magic circle looks like a complete graph with nn vertices, where mm edges are colored red and other edges are colored blue. Note that a complete graph is a simple undirected graph in which every pair of distinct vertices is connected by a unique edge.

Mona realizes that if she chooses four different vertices such that the six edges between these four vertices are of the same color, she will get a key from the magic circle. If the color is red, she will get a red key, and if the color is blue, she will get a blue key.

Base on the information written in the ancient books Mona has read, the magic power of the ancient magic circle is the absolute difference between the number of red keys and the number of the number of blue keys she can get from the magic circle.

Mona needs your help badly, since calculating the magic power of the magic circle is really a tough job.

입력

There is only one test case in each test file.

The first line of the input contains two integers nn and mm (4≤n≤1054 \le n \le 10^5, 0≤m≤min⁡(n(n−1)2,2×105)0 \le m \le \min(\frac{n(n-1)}{2}, 2 \times 10^5)) indicating the number of vertices and the number of edges colored red of the ancient magic circle.

For the following mm lines, the ii-th line contains two integers u_iu\_i and v_iv\_i (u_i<v_iu\_i < v\_i) indicating a red edge connecting vertices u_iu\_i and v_iv\_i. It is guaranteed that each edge appears at most once.

출력

Output one line containing one integer indicating the magic power of the ancient magic circle.

힌트

For the sample case, there is only one red key (1,2,3,4)(1,2,3,4) and there are four blue keys (1,5,6,7)(1,5,6,7), (2,5,6,7)(2,5,6,7), (3,5,6,7)(3,5,6,7) and (4,5,6,7)(4,5,6,7) in the ancient magic circle, thus the magic power of the magic circle is ∣1−4∣=3|1-4|=3.

예제1

  1. 예제 1

    입력
    7 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    
    예상 출력
    3