B. Princesses and Princes

B. Princesses and Princes

B.公主和王子

time limit per test: 2 seconds
每次测试的时间限制:2秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input. standard input
投入。标准输入

output: standard output
产出:标准产出

The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his
伯兰·波利卡什国王LXXXIV有n个女儿。为了在邻国建立他的权力,他想和他的王国结婚

daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well.
这些王国的王子的女儿们。幸运的是,还有其他王国。

So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of
因此,波利卡姆LXXXIV列举了他从1到n的女儿和从1到n的王国。他为每一个女儿编制了一份清单。

kingdoms princes of which she wanted to marry.
她想娶的王国的王子。

Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another.
波利卡LXXXIV非常忙,所以他为他的女儿们找到了一对又一个贪婪的夫妇。

For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the
对于第一个女儿,他从她的名单上取下了数量最少的王国,并将女儿嫁给了他们的王子。为

second daughter he takes the kingdom with the lowest number from her list, prince of which hasn’t been taken already. If there are
他的第二个女儿从她的名单中得到了数字最低的王国,而她的王子还没有被带走。如果有

no free princes in the list then the daughter maries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after
名单上没有自由的王子,那么女儿就没有人结婚,波里卡斯LXXXIV继续给下一个女儿。过程结束后

the n-th daughter.
第二个女儿。

For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3]. [1, 2]. [3, 4]. [3], respectively.
例如,如果有4个女儿和王国,女儿的名单是[2,3]。[1,2]。[3,4]。[3]分别。

In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of
在这种情况下,女儿1与王国的王子结婚2,女儿2与王国的王子结婚,女儿3与国王的王子结婚。

kingdom 3, leaving daughter 4 nobody to marry to.
kingdom 3, leaving daughter 4 nobody to marry to.

    • Cont
      -+Cont

Actually, before starting the marriage process Polycarp L XXXIV has the time to convince one of his daughters that some prince is also
Actually, before starting the marriage process Polycarp L XXXIV has the time to convince one of his daughters that some prince is also

worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter’s list. Note that this
值得嫁给。实际上,这意味着他可以在他女儿的名单中添加一个王国。注意这个

kingdom should not be present in the daughter’s list.
王国不应出现在女儿的名单上。

● Tuto
图托

Polycarp LXXXIV wants to increase the number of married couples.
PolycaroLXXXIV希望增加已婚夫妇的数量。

Unfortunately, what he doesn’t have the time for is determining what entry to add. If there is no way to increase the total number of married
不幸的是,他没有时间决定添加什么条目。如果没有办法增加结婚总数

couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of maried couples
然后,夫妇们得出的结论是,婚姻已经是最理想的了。否则,请找到这样一个条目,即已婚夫妇的总数。

increases if Polycarp LXXXIV adds it.
如果PolycaroLXXXIV添加它,则会增加。

If there are multiple ways to add an entry S0 that the total number of married couples increases then print any of them.
如果有多种方法添加已婚夫妇总数增加的条目S0,则打印其中任何一项。

For your and our convenience you are asked to answer t independent test cases.
为了您和我们的方便,我们要求您回答独立的测试用例。

Input
输入

The first line contains a single integert(1≤t < 10*)- the number of test cases.
第一行包含一个整数(1≤t<10*)–测试用例的数量。

Then t test cases follow.
然后是测试用例。

The first line of each test case contains a single integern(1 ≤n < 105)- the number of daughters and the number of kingdoms.
每个测试用例的第一行包含一个整数(1≤n<105)–女儿数和王国数。

Each of the next n lines contains the description of each daughter’s list. The first integerk(0≤k≤n) is the number of entries in the i-th
下面n行中的每一行都包含对每个女儿列表的描述。第一个整数(0≤k≤n)是i-th中的条目数。

daughter’s list. After that k distinct integers fllo 9;[1], gl[]…[9(1 < g;[j] ≤n)- the indices of the kingdoms in the list in the
daughter’s list. After that k distinct integers fllo 9;[1], gl[]…[9(1 < g;[j] ≤n)- the indices of the kingdoms in the list in the

increasing order(9;[1] < 9;[2]< … < 9;[R)-
递增顺序(9;[1]<9;[2]<.<9;[R]-

It’s guaranteed that the total number of daughters over all test cases does not exceed 10
保证所有测试用例的女儿总数不超过10个

It’s also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 105.
它还保证所有测试用例列表中的王国总数不超过105个。

模拟

int t, n, k, x;
int a[100007], done[100007];

int main(){
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1; i<=n; ++i)
            a[i] = done[i] = 0;

            for(int i=1; i<=n; ++i){
               cin>>k;
                for(int j=1; j<=k; ++j){
                    cin>>x;
                    if(!a[i] && !done[x])
                        a[i] = done[x] = 1;
                }
            }
            int f = 0, i, j;
            for(i=1; i<=n; ++i){
                if(!a[i])
                    for(j=1; j<=n; ++j)
                        if(!done[j])
                        {
                            f = 1;
                            break;
                        }
                if(f)break;
            }
            if(f)	printf("IMPROVE\n%d %d\n", i, j);
            else		printf("OPTIMAL\n");
    }
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值