Home PAT 1134 Vertex Cover
Post
Cancel

PAT 1134 Vertex Cover

Link

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cmath>
using namespace std;
int n,m,k;
bool v[10010];
vector<int>vertex[10010];
int main() {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i){
        int v1,v2;
        scanf("%d%d",&v1,&v2);
        vertex[v1].push_back(i);
        vertex[v2].push_back(i);
    }
    scanf("%d",&k);
    while(k--){
        int num,u;
        scanf("%d",&num);
        memset(v,false,sizeof(v));
        for(int i=1;i<=num;++i){
            scanf("%d",&u);
            for(int j=0;j<vertex[u].size();++j)
                v[vertex[u][j]]=true;
        }
        bool flag=true;
        for(int i=1;i<=m;++i)
            if(!v[i]){
                flag=false;
                break;
            }
        if(flag) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}
This post is licensed under CC BY 4.0 by the author.