I need to count a number of bridges in graph, but when I put a test with over 100000 vertexes I randomly get a stackoverflow, sometimes I get a right result and sometimes I get stackoverflow. What does go wrong? (lane 9, to= j.next)
public int findBridgeshelp(int v, int p, boolean[] used, int[] tin, int[] fup, int timer){
used[v] = true;
tin[v] = fup[v] = timer++;
Iterator<Integer> j = lists[v].iterator();
int count=0;
for (int i=0; i<lists[v].size(); ++i) {
int to=0;
if(j.hasNext())
to= j.next();
if (to == p) continue;
if (used[to])
fup[v] = Math.min(fup[v], tin[to]);
else {
count=count+ findBridgeshelp(to, v, used, tin, fup, timer);
fup[v] = Math.min(fup[v], fup[to]);
if (fup[to] > tin[v])
count++;
}
}
return count;
}