爪是一个点连三条边,若满足条件,点的个数满足n*2=m*3,中心点是一个集合,三条边连的点是一个集合,是二分图
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
const int maxn = 300 + 5;
int color[maxn];
vector<int> G[maxn];
bool bipartite(int u){
for(int i = 0;i < G[u].size();i++){
int v = G[u][i];
if(color[v] == color[u]) return false;
if(!color[v]){
color[v] = 3 - color[u];
if(!bipartite(v)) return false;
}
}
return true;
}
int main(){
int n,m;
while(scanf("%d",&n)){
if(n == 0) break;
int a,b;
m = 0;
memset(color,0,sizeof(color));
for(int i = 0;i <= n;i++) G[i].clear();
while(scanf("%d%d",&a,&b)){
if(a == 0 && b == 0) break;
G[a].push_back(b); G[b].push_back(a);
m++;
}
color[1] = 1;
if(bipartite(1))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}