Problem with submit

'''
class Solution {
private:
bool dfs(int node, vector &color, vector<vector > graph, int p_s)
{
color[node] = p_s;
p_s %= 2;
p_s ++;
bool ans = true;
for(int conn: graph[node])
{
if(color[conn] == 0)
{
ans = ans & dfs(conn, color, graph, p_s);
if(ans == false)
break;
}
else if(color[conn] == color[node])
return false;
}
return ans;
}

public:
bool possibleBipartition(int N, vector<vector>& dislikes){
vector color(N, 0);
vector<vector > graph(N);
for(vector q: dislikes)
{
graph[q[0] - 1].push_back(q[1] - 1);
graph[q[1] - 1].push_back(q[0] - 1);
}
bool ans = true;
for(int i = 0; i < N ; i ++)
{
if(color[i] == 0)
{
ans &= dfs(i, color, graph, 1);
if(ans == false)
break;
}
}
return ans;
}
};
static int fastio = {
#define endl '\n'
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(0);
return 0;
}();

'''
My code was running in correctly in the run button but when I submitted it ,it showed TLE on the test cases even on which it was running with run code .

Comments (0)