Codeforces Div.2 1798B Three Sevens题解

news/2024/10/19 13:34:30/

题目:

传送门

B. Three Sevens

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Lottery "Three Sevens" was held for m days. On day i, ni people with the numbers ai,1,…,ai,ni,participated in the lottery.

It is known that in each of the m days, only one winner was selected from the lottery participants. The lottery winner on day i was not allowed to participate in the lottery in the days from i+1 to m.

Unfortunately, the information about the lottery winners has been lost. You need to find any possible list of lottery winners on days from 11 to m or determine that no solution exists.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤50000). The description of the test cases follows.

The first line of each test case contains a single integer m (1≤m≤50000) — the number of days in which the lottery was held.

Next, for each i from 11 to m, follows a two-line block of data.

The first line of each block contains a single integer ni (1≤ni≤50000) — the number of lottery participants on day i.

The second line of the block contains integers ai,1,…,ai,ni (1≤ai,j≤50000) — lottery participants on day i. It is guaranteed that all the numbers ai,1,…,ai,ni are pairwise distinct.

It is guaranteed that the sum of ni over all blocks of all test cases does not exceed 5000050000.

Output

For each test case, if there is no solution, print a single integer −1−1.

Otherwise, print mintegers p1,p2,…,pm (1≤pi≤50000) — lottery winners on days from 11 to m. If there are multiple solutions, print any of them.

Sample 1

InputcopyOutputcopy
 

3

3

4

1 2 4 8

3

2 9 1

2

1 4

2

2

1 2

2

2 1

4

4

1 2 3 4

1

1

1

4

1

3

8 2 1 
-1
2 1 4 3 

 Note

In the first test case, one of the answers is [8,2,1][8,2,1] since the participant with the number 88 participated on day 11, but did not participate on days 22 and 33; the participant with the number 22 participated on day 22, but did not participate on day 33; and the participant with the number 11 participated on day 33. Note that this is not the only possible answer, for example, [8,9,4][8,9,4] is also a correct answer.

In the second test case, both lottery participants participated on both days, so any possible lottery winner on the day 11 must have participated on the day 22, which is not allowed. Thus, there is no correct answer.

In the third test case, only one participant participated on days 22, 33, 44, and on day 11 there is only one participant who did not participate in the lottery on days 2,3,42,3,4 — participant 22, which means [2,1,4,3][2,1,4,3] is the only correct answer to this test case.


分析:

就是给几个数组,分别对应天数,如果一个数在第一天出现了,第二天没出现,可能就是这小子中奖了,然后答案就是输出可能的中奖名单。


code

#include<bits/stdc++.h>
using namespace std;
int m, n;
set<int> st[50005];
int ans[50005];void sol() 
{cin >> m;for (int i = 1; i <= m; i++) {st[i].clear();cin >> n;for (int j = 1; j <= n; j++) {int x;cin >> x;st[i].insert(x);}}set<int> tot;for (int i = m; i >= 1; i--) {bool flag = false;for (int x : st[i]) {if (tot.find(x) == tot.end()) {flag = true;ans[i] = x;}tot.insert(x);}if (!flag) {printf("-1\n");return;}}for (int i = 1; i <= m; i++) {printf("%d ", ans[i]);}printf("\n");
}
int main()
{int t;cin >> t;while (t--){sol();}
}


http://www.ppmy.cn/news/107132.html

相关文章

【C++】pthread

一、pthread简介 pthread是C98接口且只支持Linux&#xff0c;使用时需要包含头文件#include <pthread.h>&#xff0c;编译时需要链接pthread库&#xff0c;其中p是POSIX的缩写&#xff0c;而POSIX是Portable Operating System Interface的缩写&#xff0c;是IEEE为要在各…

如何在竞争激烈的市场环境下打造技术铁粉:CSDN的案例分析

如何在竞争激烈的市场环境下打造技术铁粉&#xff1a;CSDN的案例分析 随着互联网的快速发展&#xff0c;技术平台不仅成为了人们获取信息、学习知识和交流经验的重要渠道&#xff0c;也成为了各大企业和个人展示自我、争夺市场份额的关键竞技场。在这个过程中&#xff0c;CSDN…

Ansible基础1——介绍安装、清单文件、配置文件、临时命令参数、常用功能模块

文章目录 一、发展起源1.1 自动化工具对比1.2 Ansible介绍 二、安装流程2.1 安装清单2.2 系统初始化2.3 安装验证 三、清单文件3.1 默认静态清单3.2 自定义静态清单 四、配置文件4.1 优先级4.2 配置参数4.2.1 [defaults]配置4.2.2 [privilege_escalation]配置4.2.3 其他配置 4.…

pytorch 绘制一维热力图

热力图 热力图&#xff08;Heat Map&#xff09;是指用 X 轴 和 Y 轴 表示的两个分类字段确定数值点的位置&#xff0c;通过相应位置的矩形颜色去表现数值的大小&#xff0c;颜色深代表的数值大。 热力图是非常特殊的一种图&#xff0c;可以显示不可点击区域发生的事情。热力…

流马平台连接数据库

新增数据库配置 在环境管理处对于环境下新增数据库配置 编辑SQL 在用例管理-步骤编辑-逻辑控件处添加前置SQL&#xff0c;编辑SQL 选择数据库名称&#xff0c;查询语句&#xff0c;填写要保存的变量名&#xff0c;并在下方填写查询语句 示例从user表中取出username和passwo…

【ROS】如何让ROS中节点实现数据交换Ⅱ --服务通信

Halo&#xff0c;这里是Ppeua。平时主要更新C语言&#xff0c;C&#xff0c;数据结构算法…感兴趣就关注我吧&#xff01;你定不会失望。 本章将介绍如何通过服务通信的方式实现节点数据交换以及ROS相关指令 本章将介绍如何通过服务通信的方式实现节点数据交换以及ROS相关指令…

制造可靠性,我关注的点(总论)

在我过去处理的事件中&#xff0c;有许多是和制造、售后&#xff08;含售后人员及用户&#xff09;相关的。 先谈下制造可靠性&#xff0c;本文先做个总论&#xff0c;后面再针对具体的几点另外写几篇文章。 针对制造&#xff0c;从可靠性角度&#xff0c;我主要关注如下几点…

安卓手机使用Termux搭建Hexo个人博客网站【内网穿透公网访问】

文章目录 1. 安装 Hexo2. 安装cpolar内网穿透3. 公网远程访问4. 固定公网地址 转载自cpolar极点云的文章&#xff1a;安卓手机使用Termux搭建Hexo个人博客网站【内网穿透公网访问】 Hexo 是一个用 Nodejs 编写的快速、简洁且高效的博客框架。Hexo 使用 Markdown 解析文章&#…