For the input 1,[ ] the expected output shown is "Special judge: No expected output available." why is it so ?


  • 0
    K

    class Solution {
    public:
    vector<int> findOrder(int numCourses, vector<pair<int, int>>& prerequisites)
    {
    map<int,unordered_set<int> > graph;
    for(int i=0;i<prerequisites.size();i++)
    {
    int x = prerequisites[i].first;
    int y = prerequisites[i].second;
    graph[x].insert(y);
    }
    if(graph.size() == 0 || prerequisites.size() == 0)
    {
    vector<int> temp;
    return temp;
    }
    vector<int> stk;
    vector<int> visited;
    for(int i=0;i<numCourses;i++)
    {
    visited.push_back(0);
    stk.push_back(0);
    }
    for(int i=0;i<numCourses;i++)
    {
    if(visited[i] == 0)
    {
    visited[i] = 1;
    stk[i] = 1;
    if(detect_cycle(graph,i,visited,stk))
    {
    vector<int> temp;
    return temp;
    }
    }
    }
    return order;
    }
    bool detect_cycle(map<int,unordered_set<int> >&graph,int i,vector<int>& visited,vector<int>& stk)
    {
    unordered_set<int>::iterator it=graph[i].begin();
    for(;it != graph[i].end();it++)
    {
    if(stk[*it] == 1)
    {
    return true;
    }
    else
    {
    if(visited[*it] == 0)
    {
    visited[*it] = 1;
    stk[*it] = 1;
    if(detect_cycle(graph,*it,visited,stk))
    {
    return true;
    }
    }
    }
    }
    stk[i] = 0;
    order.push_back(i);
    return 0;
    }
    private:
    vector<int> order;
    };


Log in to reply
 

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