我今天学习了Cut顶点和Bridges算法,并通过解决Spoj和Codechef上的几个基本问题立即对它们进行了测试。我在两个评分器上提交的两个代码都给了我相同的运行时错误- NZEC (非零退出代码)
其中一个问题是SPOJ上的Submerging Islands。
我们需要打印图形中的节点数。下面是我的代码:
Submerging Islands
它似乎适用于我能想到的所有可能的输入,但给出了相同的NZEC错误。在过去的五个小时里,我一直在尝试调试我的代码,但是失败了。使用的内存对我来说似乎很好,我认为不会有任何异常发生的可能性。我的代码出现这个NZEC错误的原因是什么?
我试图调试和测试我的代码,以确定错误的位置,但它似乎位于两个代码共同的dfs函数中。下面是dfs函数:
static void dfs (int u , boolean isRoot)
{
int child=0;
visited[u]=1;
disc[u]=++time;
low[u]=disc[u];
int sz = map.get(u).size();
for(int i=0;i<sz;i++)
{
int v = map.get(u).get(i);
if(visited[v]!=1)
{
child++;
parent[v]=u;
dfs(v,false);
// Check if the subtree rooted with v has a connection to one of the ancestors of u
low[u] = Math.min(low[u],low[v]);
// u is an articulation point in following cases
// (1) u is root of DFS tree and has two or more chilren.
if (isRoot&& child>=2)
ap[u]=1;
// (2) If u is not root and low value of one of its child is more
// than discovery value of u.
if ( !isRoot && low[v] >= disc[u])
ap[u]=1;
}
else if (v != parent[u])
low[u] = Math.min(low[u], disc[v]);
}
}NZEC错误的原因是什么?
发布于 2016-04-28 07:35:07
我用DFS试过这个问题,即在淹没一个点后,我们可以到达多少个城市组,最初所有城市都是连接的,因此组的总数将是一个,但如果在淹没一个点后,城市断开的任何部分将导致多个组,因此,我们将计数器加1。在淹没每个点后重复此迭代,以获得结果。这种方法为我带来了TLE。
https://stackoverflow.com/questions/29193893
复制相似问题