天梯赛--分而治之

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> ve[1000000];
int a[1000000]={0};//用以存放顶点的邻接点的个数
int b[1000000];
int i,V,E;
bool fun()
{
int i;
for(i=1;i<=V;i++)
if(b[i]>0)
return false;
return true;
}
int main()
{
cin>>V>>E;
vector<string> re;
for(i=0;i<E;i++)
{
int v1,v2;
cin>>v1>>v2;
a[v1]++;
a[v2]++;
ve[v1].push_back(v2);
ve[v2].push_back(v1);
}
int K;
cin>>K;
for(i=0;i<K;i++)
{
int n;
cin>>n;
int j;
for(j=1;j<=V;j++)
b[j]=a[j];
for(j=0;j<n;j++)
{
int e;
cin>>e;
b[e]=0;
int h;
for(h=0;h<ve[e].size();h++)
b[ve[e][h]]--;
}
if(fun()==false)
re.push_back("NO");
else
re.push_back("YES");
}
for(i=0;i<re.size();i++)
cout<<re[i]<<endl;
return 0;
}

猜你喜欢

转载自www.cnblogs.com/yang--xin/p/10661743.html