1134 Vertex Cover (25 分)【难度: 一般 / 知识点: 模拟】

在这里插入图片描述
https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088

#include<bits/stdc++.h>
using namespace std;
int n,m,a,b; 
vector<pair<int,int>>ve;
int main(void)
{
    
    
    cin>>n>>m;
    for(int i=0;i<m;i++) scanf("%d%d",&a,&b),ve.push_back({
    
    a,b});
    int k; cin>>k;
    for(int i=0;i<k;i++)
    {
    
    
        unordered_map<int,int>hush;
        int t,x; scanf("%d",&t);
        for(int j=0;j<t;j++) scanf("%d",&x),hush[x]++;
        bool flag=true;
        for(int j=0;j<ve.size();j++)
        {
    
    
            a=ve[j].first,b=ve[j].second;
            if(!hush[a]&&!hush[b]) flag=false;
            if(!flag) break;
        }
        if(flag) puts("Yes");
        else puts("No");
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_46527915/article/details/121548922