Vertex Cover
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=10010;
int n,m;
bool st[maxn];
struct node
{
int a,b;
}Node[maxn];
int main()
{
cin >> n >> m;
for(int i=0; i<m; i++)
cin >> Node[i].a >> Node[i].b;
int k;
cin >> k;
while(k--)
{
int cnt;
cin >> cnt;
memset(st,false,sizeof st);
for(int i=0; i<cnt; i++)
{
int x;
cin >> x;
st[x]=true;
}
int i;
for(i=0; i<m; i++)
if(!st[Node[i].a] && !st[Node[i].b])
break;
if(i==m)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
Hamiltonian Cycle
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=410;
int n,m;
bool ans;
bool st[maxn];
int g[maxn][maxn];
int main()
{
cin >> n >> m;
while(m--)
{
int a,b;
cin >> a >> b;
g[a][b]=g[b][a]=true;
}
int k;
cin >> k;
while(k--)
{
int cnt;
cin >> cnt;
memset(st,false,sizeof st);
ans=true;
int v[maxn];
for(int i=0; i<cnt; i++)
{
cin >> v[i];
st[v[i]]=true;
}
if(cnt!=n+1)
ans=false;
if(v[0]!=v[cnt-1])
ans=false;
for(int i=0; i<cnt-1; i++)
{
if(g[v[i]][v[i+1]]==false)
{
ans=false;
break;
}
}
for(int i=1; i<=n; i++)
if(!st[i])
{
ans=false;
break;
}
if(ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}