#include "leetcode.h" class Solution { public: vector vis, col; bool isBipartite(vector> &graph) { int n = graph.size(); vis.resize(n); col.resize(n); for (int i = 0; i < n; i++) if (vis[i] == 0 && dfs(i, 0, graph) == false) return false; return true; } private: bool dfs(int v, int c, vector> &graph) { vis[v] = 1; col[v] = c; for (int child : graph[v]) if (vis[child] == 0) { if (dfs(child, c ^ 1, graph) == false) return false; } else if (col[v] == col[child]) return false; return true; } }; int main() {}