LCR 106. 判断二分图 - 力扣(LeetCode)
超时代码:
class Solution {public:int work1[110] = {0};int work2[110] = {0};bool divide(vector<vector<int>>& graph, int n){bool judge = false;if(n >= graph.size()){for(int i = 0; i < n; i++){for(int j = 0; j < graph[i].size(); j++){if((work1[graph[i][j]] && work1[i]) || (work2[i] && work2[graph[i][j]])){return false;}}}return true;}work1[n] = 1;judge = judge || divide(graph, n+1);if(judge) return judge;work1[n] = 0;work2[n] = 1;judge = judge || divide(graph, n+1);work2[n] = 0;return judge;}bool isBipartite(vector<vector<int>>& graph) {return divide(graph, 0);}};