Codeforces 615A Bulbs 【水题】

这篇博客探讨了Codeforces 615A问题,其中Vasya试图通过按下按钮来开启m个圣诞灯泡。每个按钮控制一些灯泡,目标是确定是否能点亮所有灯泡。输入包括按钮数量n和灯泡数量m,以及每个按钮控制的灯泡编号。如果可能全部点亮灯泡,则输出'YES',否则输出'NO'。博客提到了一个样本案例并提供了AC(Accepted)代码。
摘要由CSDN通过智能技术生成

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".

Sample test(s)
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
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.


题意:n个开关控制m个灯,按下开关会把对应控制的灯打开(已经打开的状态不变),问能否把所有灯全打开。


AC代码:


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (500000)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 10007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
#define PI acos(-1.0)
using namespace std;
bool vis[110];
int main()
{
    int t;
    int n, m; Ri(n); Ri(m);
    CLR(vis, false);
    for(int i = 0; i < n; i++)
    {
        int a, b;
        Ri(a);
        W(a)
        {
            Ri(b);
            vis[b] = true;
        }
        //vis[a] = true;
    }
    bool flag = true;
    for(int i = 1; i <= m; i++)
    {
        if(!vis[i])
        {
            flag = false;
            break;
        }
    }
    printf(flag ? "YES\n" : "NO\n");
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值