Bulbs
来源:互联网 发布:mac相册导入移动硬盘 编辑:程序博客网 时间:2024/05/18 02:26
Bulbs
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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”.
Sample Input
Input
3 4
2 1 4
3 1 3 1
1 2
Output
YES
Input
3 3
1 1
1 2
1 1
Output
NO
Hint
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.
一道水题,但还是花了好多时间,只要把个数据扫一遍,看看是否都存在即可。
代码如下:
#include<cstdio>int main(){ int n,m,a[111],k,t,i,j,o; while(~scanf("%d %d",&n,&m)){ for(i=1;i<=m;i++){ a[i]=0; } for(i=0;i<n;i++){ scanf("%d",&k); while(k--){ scanf("%d",&t); a[t]=1; } } o=1; for(i=1;i<=m;i++){ if(a[i]==0){ o=0; break; } } if(o) printf("YES\n"); else printf("NO\n"); } return 0;}
- Bulbs
- Bulbs
- Bulbs
- Bulbs
- Bulbs
- hdoj5600N bulbs
- A. Bulbs
- CF615A Bulbs
- Codeforces Bulbs
- H - Bulbs
- 【codeforces】Bulbs
- 【codeforces】Bulbs
- ZOJ - 2976 Light Bulbs
- BNU16495:Light Bulbs
- HDOJ 5600 N bulbs
- hdu 5600 N bulbs
- hdu5601 N*M bulbs
- HDU 5600:N bulbs
- hdoj-5019-Revenge of GCD
- Android DrawableAnimation逐帧动画加载多图(OOM的解决)
- CodeForces599BSpongebob and Joke
- Java 进阶 之 序列化
- PAT-B 1009. 说反话
- Bulbs
- 训练之DP-数塔
- Adaboost ,gbdt 原理详解
- Android开发环境搭建和模拟器创建
- navicat从下载到使用
- 通过xml处理sql语句时对小于号与大于号的处理转换
- org.w3c.dom中节点添加属性,没有一定的顺序,但是dom4j中添加的属性是有顺序的
- 【慕课学习】《JavaScript深入浅出》——javascript数据类型
- UVA - 575 Skew Binary