//determine whether the figure G is a two-point graph, you can use the staining method. //from one o'clock onwards, the point map of his adjacency is a different color, so long as the BFS a lap map. If you encounter the same color in the picture,//indicates that 2 points are connected, so it is not;#include <stdio.h>#include<string.h>#include<queue>using namespacestd;#defineMAXN 210intMAP[MAXN][MAXN],COLOR[MAXN];intBFsintUintN) { inti; Queue<int>Q; Q.push (U); Color[u]=1; while(!Q.empty ()) { intv=Q.front (); Q.pop (); for(i=1; i<=n;i++) { if(color[i]==-1&&Map[v][i]) {Q.push (i); Color[i]=!Color[v]; } if(color[i]==color[v]&&Map[v][i])return 0; } } return 1;}intMain () {inti,j,n,m; while(SCANF ("%d%d", &n,&m)! =EOF) {memset (color,-1,sizeof(color)); memset (Map,0,sizeof(map)); for(i=0; i<m;i++) { intx, y; scanf ("%d%d",&x,&y); Map[x][y]=map[y][x]=1; } intflag=1; for(i=1; i<=n;i++) { if(color[i]==-1&&!BFS (i,n)) {Flag=0; Break; } } if(flag) printf ("yes\n"); Elseprintf"no\n"); }}
Two-part chart judging (template)