Why is my solution incorrect?

programming
Tags: #<Tag:0x00007f24241f7828>

#1

int white = 0; //not visited
int grey = 1; //current dfs on
int black = 2; //visited dfs completed
bool backedge = false;

void dfs(int x, vector<int> &vis, vector<int> adj[])
{
    if(backedge)
        return;
    
    vis[x] = 1;
    for(auto it : adj[x])
    {
        //it = to node
        if(vis[it] == 0)
        {
            //not visited , so do dfs
            dfs(it, vis, adj);
        }
        if(vis[it] == 1)
        {
            backedge = true;
        }
    }
    vis[x] = 2;
    
    
}

int Solution::solve(int A, vector<int> &B, vector<int> &C) 
{
    vector<int> adj[A + 1];
    for (int i = 0; i <= A; i++)
    {
        adj[i].clear();
    }

    vector<int> vis(A + 10, 0);
    // memset(vis, 0, sizeof vis);

    int edges = B.size();
    for (int i = 0; i < edges; i++)
    {
        int from = B[i];
        int to = C[i];
        adj[from].push_back(to);
    }

    // int i = 0;
    // for (auto it : adj)
    // {
    //     cout << i << " : ";
    //     for (auto it2 : it)
    //     {
    //         cout << it2 << " ";
    //     }
    //     cout << endl;
    //     i++;
    // }

    for (int i = 1; i <= A; i++)
    {
        if (!vis[i])
        {
            dfs(i, vis, adj);
            if (backedge)
                // return 0;
            {return 0;}
        }
    }
    return 1;
    // cout << 1 << endl;
}