Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这题数据确实有环啊

Posted by xiao1590 at 2017-03-09 10:55:33 on Problem 3660
从一个节点出发,深度优先遍历可到达的所有节点,以在邻接矩阵中建立直接的i->关系
但是如果不用visited数组标记是否访问过,就会TLE。
求解,我的逻辑有错误吗?如果有环说明M个数据中有矛盾,那所谓的ranking还有意义么…
floyd算法的3个for循环不会受环的影响,所以可能很多人没注意实际数据是否有环
void Dfs(int startNode, int currentNode)
{
    visited[currentNode] = 1;
    for (int i = 1; i <= n; i++)
    {
        if (g[currentNode][i])
        {
            g[startNode][i] = 1;
            //printf("%d->%d\n", startNode, i);
            if (!visited[i]) Dfs(startNode, i);
        }
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator