首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【CodeForces】615A - Bulbs(水)

【CodeForces】615A - Bulbs(水)

作者头像
FishWang
发布2025-08-26 15:27:25
发布2025-08-26 15:27:25
12500
代码可运行
举报
运行总次数:0
代码可运行

点击打开题目

A. Bulbs

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?

If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.

Input

The first line of the input contains integers n and m (1 ≤ n, m ≤ 100) — the number of buttons and the number of bulbs respectively.

Each of the next n lines contains xi (0 ≤ xi ≤ m) — the number of bulbs that are turned on by the i-th button, and then xi numbers yij(1 ≤ yij ≤ m) — the numbers of these bulbs.

Output

If it's possible to turn on all m bulbs print "YES", otherwise print "NO".

Examples

input

代码语言:javascript
代码运行次数:0
运行
复制
3 4
2 1 4
3 1 3 1
1 2

output

代码语言:javascript
代码运行次数:0
运行
复制
YES

input

代码语言:javascript
代码运行次数:0
运行
复制
3 3
1 1
1 2
1 1

output

代码语言:javascript
代码运行次数:0
运行
复制
NO

Note

In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.

按按钮不会关灯,那就全按了。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
int main()
{
	bool light[111];
	int n,m;
	while (~scanf ("%d %d",&n,&m))
	{
		for (int i = 1 ; i <= m ; i++)
			light[i] = false;
		for (int i = 1 ; i <= n ; i++)
		{
			int tn;
			scanf ("%d",&tn);
			while (tn--)
			{
				int t;
				scanf ("%d",&t);
				light[t] = true;
			}
		}
		bool ans = true;
		for (int i = 1 ; i <= m ; i++)
		{
			if (!light[i])
			{
				ans = false;
				break;
			}
		}
		if (ans)
			printf ("YES\n");
		else
			printf ("NO\n");
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档