Is Graph Bipartite? Posted on 2018-10-06 Descriptionhttps://leetcode.com/problems/is-graph-bipartite/description/ Solution123456789101112131415161718192021222324class Solution {public: bool isBipartite(vector<vector<int>>& graph) { int size = graph.size(); if (size == 1) return true; vector<int> colors(size, 0); for (int i = 0; i < size; ++i) { if (colors[i] != 0) continue; if (dfs(i, colors, graph, 1) == false) return false; } return true; } bool dfs(int index, vector<int>& colors, vector<vector<int>>& graph, int color) { if (colors[index] != 0) return colors[index] == color; colors[index] = color; vector<int>& near = graph[index]; for (int item : near) { if (dfs(item, colors, graph, -color) == false) return false; } return true; }};