Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool bp = true;
- void dfs(int node , vector<vector<int>>&g , vector<int>&color){
- for(int x : g[node]){
- if(color[x] == -1){
- color[x] = 1-color[node];
- dfs(x,g,color);
- }
- else if(color[x] == color[node]){
- bp = false;
- }
- }
- }
- bool isBipartite(vector<vector<int>>& graph) {
- int n = graph.size();
- vector<int>color(n,-1);
- for(int a=0;a<n;a++){
- if(color[a] == -1){
- color[a] = 0;
- dfs(a,graph,color);
- }
- }
- return bp;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement