HELP ME !!!why it's wrong


  • -1
    S

    0_1497862997495_7fd90808-69af-4157-9b40-2719d11fd245-image.png 0_1497862993472_a18b8f4e-3ed5-48ba-b30c-a0e4d28b221b-image.png
    ...
    int a[2600][2600],vis[2600],swi;
    int dfs(int n,int v){
    vis[v] = -1;
    for(int i = 0; i <n; i++)
    {
    if(a[v][i] != 0 && !vis[i]) {
    dfs(n,i);
    vis[i]=1;
    }
    if(a[v][i] != 0 && vis[i] == -1){
    swi=true;
    return true;
    }
    }
    return false;
    }
    class Solution {
    public:
    bool canFinish(int numCourses, vector<pair<int, int> >& prerequisites) {
    int num=prerequisites.size();
    if(num==0)return true;
    memset(a,0,sizeof(a));
    memset(vis,0,sizeof(vis));
    for(int i=0;i<num;i++){
    int l=prerequisites[i].first;
    int r=prerequisites[i].second;
    a[l][r]=1;
    }
    dfs(numCourses,0);
    if(!swi) return true;
    else return false;
    }
    };
    ...


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.