QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480303#999. 边双连通分量_l_l_#WA 0ms41944kbC++141.2kb2024-07-16 13:02:512024-07-16 13:02:51

Judging History

你现在查看的是最新测评结果

  • [2024-07-16 13:02:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:41944kb
  • [2024-07-16 13:02:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
vector<int> G[MAXN]; int dfn[MAXN], low[MAXN], col[MAXN], times;
bool instk[MAXN]; stack<int> stk; int btot;
vector<int> G2[MAXN], scc[MAXN]; int deg[MAXN];
void tarjan(int u) {
	dfn[u] = low[u] = ++times; instk[u] = 1; stk.push(u); for (int v : G[u]) {
		if (dfn[v] == 0) tarjan(v), low[u] = min(low[u], low[v]);
		else if (instk[v]) low[u] = min(low[u], dfn[v]);
	}
	if (low[u] == dfn[u]) {
		int y; btot++; do {
			y = stk.top(); stk.pop(); instk[y] = 0; scc[col[y] = btot].push_back(y);
		} while (y != u);
	}
}
int main() {
	int n, m; scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d %d", &u, &v); u++; v++;
		G[u].push_back(v);
	}
	for (int i = 0; i < n; i++) if (dfn[i] == 0) tarjan(i);
	for (int i = 0; i < n; i++) for (int v : G[i]) {
		if (col[i] != col[v]) G2[col[i]].push_back(col[v]), deg[col[v]]++;
	}
	queue<int> q; for (int i = 1; i <= btot; i++) if (deg[i] == 0) q.push(i);
	printf("%d\n", btot); while (q.empty() == 0) {
		int u = q.front(); q.pop();
		printf("%d", (int)scc[u].size()); for (int v : scc[u]) printf(" %d", v - 1); puts("");
		for (int v : G2[u]) if (--deg[v] == 0) q.push(v);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 41944kb

input:

4 5
0 2
0 1
3 0
2 1
2 3

output:

3
1 -1
3 3 2 0
1 1

result:

wrong answer Integer -1 violates the range [0, 3]