CF1070M.Algoland and Berland

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Once upon a time Algoland and Berland were a single country, but those times are long gone. Now they are two different countries, but their cities are scattered on a common territory.

All cities are represented as points on the Cartesian plane. Algoland consists of aa cities numbered from 11 to aa . The coordinates of the ii -th Algoland city are a pair of integer numbers (xai,yai)(xa_i, ya_i) . Similarly, Berland consists of bb cities numbered from 11 to bb . The coordinates of the jj -th Berland city are a pair of integer numbers (xbj,ybj)(xb_j, yb_j) . No three of the a+ba+b mentioned cities lie on a single straight line.

As the first step to unite the countries, Berland decided to build several bidirectional freeways. Each freeway is going to be a line segment that starts in a Berland city and ends in an Algoland city. Freeways can't intersect with each other at any point except freeway's start or end. Moreover, the freeways have to connect all a+ba+b cities. Here, connectivity means that one can get from any of the specified a+ba+b cities to any other of the a+ba+b cities using freeways. Note that all freeways are bidirectional, which means that one can drive on each of them in both directions.

Mayor of each of the bb Berland cities allocated a budget to build the freeways that start from this city. Thus, you are given the numbers r1,r2,,rbr_1, r_2, \dots, r_b , where rjr_j is the number of freeways that are going to start in the jj -th Berland city. The total allocated budget is very tight and only covers building the minimal necessary set of freeways. In other words, r1+r2++rb=a+b1r_1+r_2+\dots+r_b=a+b-1 .

Help Berland to build the freeways so that:

  • each freeway is a line segment connecting a Berland city and an Algoland city,
  • no freeways intersect with each other except for the freeway's start or end,
  • freeways connect all a+ba+b cities (all freeways are bidirectional),
  • there are rjr_j freeways that start from the jj -th Berland city.

输入格式

Input contains one or several test cases. The first input line contains a single integer number tt ( 1t30001 \le t \le 3000 ) — number of test cases. Then, tt test cases follow. Solve test cases separately, test cases are completely independent and do not affect each other.

Each test case starts with a line containing space-separated integers aa and bb ( 1a,b30001 \le a, b \le 3000 ) — numbers of Algoland cities and number of Berland cities correspondingly.

The next line contains bb space-separated integers r1,r2,,rbr_1, r_2, \dots, r_b ( 1rba1 \le r_b \le a ) where rjr_j is the number of freeways, that should start in the jj -th Berland city. It is guaranteed that r1+r2++rb=a+b1r_1+r_2+\dots+r_b=a+b-1 .

The next aa lines contain coordinates of the Algoland cities — pairs of space-separated integers xai,yaixa_i, ya_i ( 10000xai,yai10000-10000 \le xa_i, ya_i \le 10000 ). The next bb lines contain coordinates of the Berland cities — pairs of space-separated integers xbi,ybixb_i, yb_i ( 10000xbi,ybi10000-10000 \le xb_i, yb_i \le 10000 ). All cities are located at distinct points, no three of the a+ba+b cities lie on a single straight line.

Sum of values aa across all test cases doesn't exceed 30003000 . Sum of values bb across all test cases doesn't exceed 30003000 .

输出格式

For each of the tt test cases, first print "YES" if there is an answer or "NO" otherwise.

If there is an answer, print the freeway building plan in the next a+b1a+b-1 lines. Each line of the plan should contain two space-separated integers jj and ii which means that a freeway from the jj -th Berland city to the ii -th Algoland city should be built. If there are multiple solutions, print any.

输入输出样例

  • 输入#1

    2
    2 3
    1 1 2
    0 0
    1 1
    1 2
    3 2
    4 0
    1 1
    1
    0 0
    0 1
    

    输出#1

    YES
    2 2
    1 2
    3 2
    3 1
    YES
    1 1
    
首页