题意:有n个人,m场比赛,x个人为good player,y个人为bad player,
每场比赛两个人分分别为good和bad,问good和bad是否会冲突
1 ≤ N≤ 1000,1 ≤M ≤ 10000
思路:二分图
根据已有的点暴力遍历,判有没有冲突即可
并查集也能写,队友写的搜索
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
using namespace std;
typedef long long int lint; const int MAXN = 1e3 + ;
const int MAXM = 1e4 + ; vector<int> g[MAXN];
queue<int> a,b; int n,m,x,y;
int color[MAXN]; void init(){
memset(color,-,sizeof(color));
for(int i = ; i <= n; ++i){ g[i].clear();}
while(!a.empty()){ a.pop();}
while(!b.empty()){ b.pop();}
} bool solve(){
while(!a.empty() || !b.empty()){
while(!a.empty()){
int now = a.front(); a.pop();
for(int i = ; i < g[now].size(); ++i){
if(color[g[now][i]] == -){
color[g[now][i]] = ; b.push(g[now][i]);
}else if(color[g[now][i]] == ){
return false;
}
}
}
while(!b.empty()){
int now = b.front(); b.pop();
for(int i = ; i < g[now].size(); ++i){
if(color[g[now][i]] == -){
color[g[now][i]] = ; a.push(g[now][i]);
}else if(color[g[now][i]] == ){
return false;
}
}
}
}
return true;
} int main(){
while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF){
init();
for(int i = ; i <= m; ++i){
int u,v; scanf("%d%d",&u,&v);
g[u].push_back(v); g[v].push_back(u);
}
for(int i = ; i <= x; ++i){
int num; scanf("%d",&num); a.push(num); color[num] = ;
}
for(int i = ; i <= y; ++i){
int num; scanf("%d",&num); b.push(num); color[num] = ;
}
if(!solve()){
printf("NO\n"); continue;
}
bool flag = true;
for(int i = ; i <= n; ++i){
if(color[i] == - && g[i].size() != ){
a.push(i);
if(!solve()){
flag = false; break;
}
}else if(color[i] == - && g[i].size() == ){
flag = false; break;
}
}
if(!flag){
printf("NO\n"); continue;
}else{
printf("YES\n"); continue;
}
}
return ;
}