UVA 11396 Claw Decomposition(二分图)

以“爪”形为单元,问所给出的无向图中能否被完全分割成一个个单元。

分析图的性质,由于已知每个点的度是3,所以“爪”之间是相互交错的,即把一个“爪”分为中心点和边缘点,中心点被完全占据,而边缘点被三个“爪”瓜分。分析到这里,用二分图的性质就可以解决了。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<vector>
 4 #include<queue>
 5 using namespace std;
 6 
 7 const int MAXN=333;
 8 
 9 int color[MAXN];
10 vector<int >G[MAXN];
11 queue<int >q;
12 
13 bool Bjudge()
14 {
15     memset(color,-1,sizeof(color));
16     while(!q.empty())
17         q.pop();
18     q.push(1);
19     color[1]=0;
20     while(!q.empty())
21     {
22         int i=q.front();
23         q.pop();
24         for(int j=0;j<G[i].size();j++)
25         {
26             if(color[G[i][j]]==-1){
27                 color[G[i][j]]=1-color[i];
28                 q.push(G[i][j]);
29             }else if(color[G[i][j]]==color[i])
30                 return false;
31         }
32     }
33     return true;
34 }
35 
36 int main()
37 {
38     int n,a,b;
39     while(~scanf("%d",&n))
40     {
41         if(!n)
42             return 0;
43         for(int i=1;i<=n;i++)
44             G[i].clear();
45         do{
46             scanf("%d%d",&a,&b);
47             G[a].push_back(b);
48             G[b].push_back(a);
49         }while(a&&b);
50 
51         if(Bjudge())
52             printf("YES
");
53         else
54             printf("NO
");
55     }
56     return 0;
57 }
58 /*
59 附上一组“YES”的数据
60 6
61 1 2
62 1 4
63 1 6
64 2 3
65 2 5
66 3 4
67 3 6
68 4 5
69 5 6
70 0 0
71 */
View Code
原文地址:https://www.cnblogs.com/zstu-abc/p/3242122.html