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;}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 宝宝流鼻涕一个月了怎么办 一个月婴儿感冒咳嗽流鼻涕怎么办 怎么办感冒能好得快些 一个月的宝宝流鼻涕怎么办 鼻炎犯了一直流鼻涕怎么办 宝宝流鼻涕鼻子擦破了怎么办 宝宝流鼻涕鼻子擦红了怎么办 上班忘记穿内衣了怎么办 早上上班忘记穿内衣了怎么办 高中知识都忘了怎么办 留鼻涕跟水一样怎么办 鼻涕像水一样流怎么办 肩膀很疼怎么办睡不着觉 夏天穿内衣出汗后很臭怎么办 脸过敏后严重缺水怎么办 过敏后脸上反复出现湿疹怎么办 孕妇脸上长湿疹过敏红肿怎么办 一岁宝宝一直流鼻涕怎么办 三岁宝宝一直流鼻涕怎么办 3岁宝宝一直流鼻涕不好怎么办 7岁半边鼻子不通气怎么办 感冒流鼻涕鼻子不通气怎么办 鼻子不通气干的怎么办 7个月婴儿流鼻涕怎么办 鼻子火辣辣的光想流鼻涕怎么办? 三岁宝宝鼻塞流鼻涕怎么办 一岁宝宝感冒流鼻涕鼻塞怎么办 1岁宝宝鼻塞流鼻涕怎么办 一岁多宝宝感冒鼻塞流鼻涕怎么办 宝宝鼻塞流鼻涕怎么办速效办法 八个月宝宝感冒流鼻涕鼻塞怎么办 7岁儿童流清鼻涕怎么办 1岁的宝宝流鼻涕怎么办 3岁宝宝鼻塞严重怎么办 宝宝流鼻涕2个月怎么办 一个月宝宝流鼻子怎么办 六个月宝宝流清水鼻涕怎么办 婴儿流鼻涕怎么办最简单方法 婴儿咳嗽流鼻涕怎么办最简单方法 6个月小孩流鼻涕怎么办 宝宝风寒感冒咳嗽流鼻涕怎么办