| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这题数据确实有环啊从一个节点出发,深度优先遍历可到达的所有节点,以在邻接矩阵中建立直接的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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator