H - Bulbs
来源:互联网 发布:海尔电视软件下载 编辑:程序博客网 时间:2024/05/21 21:02
H - Bulbs
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit
Status
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<iostream>#include<cstdio>#include<cstring>#include<cstring>#include<algorithm>using namespace std;int a[100]={0};//全局变量 int main(){ int n,m,i,t,b,j; while(cin>>n>>m) { for(i=1;i<=n;++i) { cin>>t; for(j=1;j<=t;++j) { cin>>b; a[b]=1; } } for(i=1;i<=m;++i) { if(a[i]==0) break; } if(i==m+1) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } } return 0; }
- H - Bulbs
- Bulbs
- Bulbs
- Bulbs
- Bulbs
- Bulbs
- hdoj5600N bulbs
- A. Bulbs
- CF615A Bulbs
- Codeforces 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
- 43. Multiply Strings
- The method setValue(String) in the type ParamTag is not applicable for the arguments (long)
- G - New Year and Days
- LeetCode - 134. Gas Station
- Git客户端TortoiseGit(Windows系统)的使用方法
- H - Bulbs
- C语言断言的应用
- PAT-B 1017. A除以B
- Spongebob and Joke
- Fedora 24 相关配置
- 切片的更多操作方法
- centos7 ip forwarding 的坑
- I - Restaurant
- Java学习-值传递