QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92326#906. 强连通分量zhaohaikun#WA 1ms13764kbC++141.4kb2023-03-30 15:55:262023-03-30 15:55:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 15:55:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:13764kb
  • [2023-03-30 15:55:26]
  • 提交

answer

#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
const int N = 2e5 + 10;
int n, m, dfn[N], low[N], sccnum[N], scccnt, dfscnt, sta[N], stacnt;
vector <int> v[N], p[N];
void dfs(int x) {
	low[x] = dfn[x] = ++dfscnt;
	sta[stacnt++] = x;
	for (int i: v[x])
		if (!dfn[i]) {
			dfs(i);
			chkmin(low[x], low[i]);
		} else if (!sccnum[i]) {
			chkmin(low[x], dfn[i]);
		}
	if (low[x] == dfn[x]) {
		scccnt++;
		do {
			sccnum[sta[--stacnt]] = scccnt;
			p[scccnt].push_back(sta[stacnt]);
		} while (sta[stacnt] != x);
	}
}
signed main() {
	read(n); read(m);
	F(i, 1, m) {
		int x, y; read(x); read(y);
		x++; y++;
		v[x].push_back(y);
	}
	F(i, 1, n)
		if (!dfn[i]) dfs(i);
	cout << scccnt << endl;
	F(i, 1, scccnt) {
		cout << p[i].size() << " ";
		for (int j: p[i]) cout << j - 1 << " "; cout << endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 13764kb

input:

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2

output:

4
2 3 0 
1 2 
2 4 1 
1 5 

result:

wrong answer 5 is later than 2, but there is an edge (5, 2)