#define pb push_back#define _for(i,a,b) for(int i = (a);i < (b);i ++)const int maxn = 50003; vector G[maxn];int V;int color[maxn];bool dfs(int v,int c){ color[v] = c; for(int i = 0;i < G[v].size();i ++) { if(color[G[v][i]] == c) return false; if(color[G[v][i]] == 0 && !dfs(G[v][i],-c)) return false; } return true;}int biGraph(){ memset(color,0,sizeof(color)); for(int i = 0;i < V;i ++) if(color[i]==0) if(!dfs(i,1)) return 0; return 1;}
biGraph()若返回0,则不能构成二分图,返回1则能。color数组里装的是每个节点的颜色。