I was trying to solve this problem: 343D. I used for each to iterate through the adjacent list in DFS and get MLE: 17028123
for (int v: adj[u]) {
if (flag[v]) continue;
DFS(v);
}
Then I switch to normal for statement and got AC: 17028517
for (int i = 0; i < adj[u].size(); ++i) {
int v = adj[u].get(i);
if (flag[v] == false) DFS(v);
}
Could someone explain why this happened, please ?