1149 Dangerous Goods Packaging (25 分)【难度: 一般 / 知识点: 哈希表】

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

#include<bits/stdc++.h>
using namespace std;
unordered_map<int,vector<int>>mp;
int n,m;
int main(void)
{
    
    
    scanf("%d%d",&n,&m);
    while(n--)
    {
    
    
        int a,b; scanf("%d%d",&a,&b);
        mp[a].push_back(b);
        mp[b].push_back(a);
    }
    while(m--)
    {
    
    
        int flag=1,k; scanf("%d",&k);
        int hush[100010]={
    
    0};
        for(int i=0;i<k;i++)
        {
    
    
            int s; scanf("%d",&s);
            if(flag)
            for(int j=0;j<mp[s].size();j++)
            {
    
    
                if(hush[mp[s][j]]) flag=0;
                if(!flag) break;
            }
            hush[s]++;
        }
        if(flag) puts("Yes");
        else puts("No");
    }
    return 0;
}

Guess you like

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