找哈密尔顿图 我的算法为什么会TLE?

0
0

class graph { multimap G; int ne, nv,count,visitednum; vector visit; public: graph(int n, int m) { G.clear(); nv = n; ne = m; int f, t; for (int i = 0; i> f >> t; G.insert(pair(f-1, t-1)); } }

int countHC()
{
    visit =  vector<int> (nv, 0);
    count = 0;
    visitednum = 0;
    DFS(0);
    return count;

}
void DFS(int v)
{
    visitednum++;
    visit[v] = 1;
    if (visitednum == nv)
    {   
        for (multimap<int, int>::iterator it = G.lower_bound(v); it != G.upper_bound(v); it++)
        {
            if (it->second==0)
            {
                count++;
                break;
            }
        }
    }
    for (multimap<int, int>::iterator it = G.lower_bound(v); it != G.upper_bound(v); it++)
    {
        if (!visit[it->second])DFS(it->second);
    }
    visit[v] = 0;
    visitednum--;
}

};

0 answer(s)

write answer 切换为英文 切换为中文


转发分享