https://leetcode.com/problems/is-graph-bipartite/
class Solution {
public:
bool isBipartite(vector<vector<int>>& graph) {
vector<int> colors(graph.size());
for(int i=0; i<graph.size(); i++){
if(colors[i]!=0) continue;
colors[i] = 1;
queue<int> Q;
Q.push(i);
while (!Q.empty()) {
int t = Q.front(); Q.pop();
for(auto a: graph[t]){
if(colors[a]==colors[t]) return false; //相同颜色
if(colors[a]==0){
colors[a] = -1*colors[t]; //换成不同颜色
Q.push(a);
}
}
}
}
return true;
}
};