CF1552C.Maximize the Intersections

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

On a circle lie 2n2n distinct points, with the following property: however you choose 33 chords that connect 33 disjoint pairs of points, no point strictly inside the circle belongs to all 33 chords. The points are numbered 1,2,,2n1, \, 2, \, \dots, \, 2n in clockwise order.

Initially, kk chords connect kk pairs of points, in such a way that all the 2k2k endpoints of these chords are distinct.

You want to draw nkn - k additional chords that connect the remaining 2(nk)2(n - k) points (each point must be an endpoint of exactly one chord).

In the end, let xx be the total number of intersections among all nn chords. Compute the maximum value that xx can attain if you choose the nkn - k chords optimally.

Note that the exact position of the 2n2n points is not relevant, as long as the property stated in the first paragraph holds.

输入格式

The first line contains a single integer tt ( 1t1001 \le t \le 100 ) — the number of test cases. Then tt test cases follow.

The first line of each test case contains two integers nn and kk ( 1n1001 \le n \le 100 , 0kn0 \le k \le n ) — half the number of points and the number of chords initially drawn.

Then kk lines follow. The ii -th of them contains two integers xix_i and yiy_i ( 1xi,yi2n1 \le x_i, \, y_i \le 2n , xiyix_i \ne y_i ) — the endpoints of the ii -th chord. It is guaranteed that the 2k2k numbers x1,y1,x2,y2,,xk,ykx_1, \, y_1, \, x_2, \, y_2, \, \dots, \, x_k, \, y_k are all distinct.

输出格式

For each test case, output the maximum number of intersections that can be obtained by drawing nkn - k additional chords.

输入输出样例

  • 输入#1

    4
    4 2
    8 2
    1 5
    1 1
    2 1
    2 0
    10 6
    14 6
    2 20
    9 10
    13 18
    15 12
    11 7

    输出#1

    4
    0
    1
    14

说明/提示

In the first test case, there are three ways to draw the 22 additional chords, shown below (black chords are the ones initially drawn, while red chords are the new ones):

We see that the third way gives the maximum number of intersections, namely 44 .

In the second test case, there are no more chords to draw. Of course, with only one chord present there are no intersections.

In the third test case, we can make at most one intersection by drawing chords 131-3 and 242-4 , as shown below:

首页