[Codeforces] [615A] Bulbs

Problem Description

Loading...

Problem Analysis

Given the bulbs each button can turn on
determine whether all bulbs can be turned on

Since a bulb that has been turned on will not turn off
any bulb controlled by a button can be turned on
that is, any bulb that appears can be turned on

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<stdio.h>
#include<string.h>
int a[120];
int main() {
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF) {
        memset(a,0,sizeof(a));
        for(int i=0; i<n; i++) {
            int t;
            scanf("%d",&t);
            while(t--) {
                int tx;
                scanf("%d",&tx);
                a[tx]=1;
            }
        }
        int i;
        for(i=1; i<=m; i++) {
            if(!a[i])
                break;
        }
        printf("%s\n",i<=m?"NO":"YES");
    }
    return 0;
}

Loading...