bool dfs(int u) { vis[u] = 1; for (int i = head[u]; i; i = edge[i].next) { int v = edge[i].to; if (vis[v] == 1) return false; if (vis[v] == 0 && !dfs(v)) return false; } vis[u] = -1; S.push(u); return true; }
bool dfs(int u) { vis[u] = 1; for (int i = head[u]; i; i = edge[i].next) { int v = edge[i].to; if (vis[v] == 1) return false; if (vis[v] == 0 && !dfs(v)) return false; } vis[u] = -1; S.push(u); return true; }