QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#342169#906. 强连通分量Network_Error#WA 0ms9688kbC++203.1kb2024-03-01 09:24:472024-03-01 09:28:48

Judging History

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

  • [2024-03-01 09:28:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9688kb
  • [2024-03-01 09:24:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define piii tuple<int, int, int>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define deb(var) cerr << #var << '=' << (var) << "; "
#define int long long
namespace IO {
	#define BF 65536
	char buf[BF], *p1 = buf, *p2 = buf;
	#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BF, stdin), p1 == p2) ? EOF : *p1++)
//	template<typename T>
	inline int uread() {
		int x = 0; char c = getchar();
		while (!isdigit(c)) c = getchar();
		while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); return x;
	}
//	template<typename T>
	inline int read() {
		int x = 0, f = 0; char c = getchar();
		while (!isdigit(c)) f |= c == '-', c = getchar();
		while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); return f ? -x : x;
	}
	char obuf[BF + 30]; int o1, o2, num[30];
	#define flush() fwrite(obuf, 1, o1, stdout), o1 = 0
	inline void putchar(const char &c) {
		obuf[o1++] = c; if (o1 >= BF) flush();
	}
//	template<typename T>
	inline void uwrite(int x) {
		do num[++o2] = x % 10; while (x /= 10);
		do obuf[o1++] = num[o2] ^ 48; while (--o2); obuf[o1++] = '\n'; if (o1 >= BF) flush();
	}
//	template<typename T>
	inline void write(const int& x) {
		if (x < 0) obuf[o1++] = '-', uwrite(-x); else uwrite(x);
	}
} using namespace IO;
namespace Maths {
	const int mod = 998244353;
	int power(int x, int y) {
		int ans = 1; while (y) {
			if (y & 1) ans = 1ll * ans * x % mod; y >>= 1; x = 1ll * x * x % mod;
		} return ans;
	}
	int power(int x, int y, int mod) {
		int ans = 1; while (y) {
			if (y & 1) ans = 1ll * ans * x % mod; y >>= 1; x = 1ll * x * x % mod;
		} return ans;
	}
	int fac[1000010], inv[1000010];
	void init() {
		fac[0] = fac[1] = inv[0] = inv[1] = 1;
		for (int i = 2; i <= 1e6; i++) fac[i] = 1ll * fac[i - 1] * i % mod, inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
		for (int i = 2; i <= 1e6; i++) inv[i] = 1ll * inv[i] * inv[i - 1] % mod;
	}
	int binom(int n, int m) {
		return n < m || m < 0 ? 0 : 1ll * fac[n] * inv[n - m] % mod * inv[m] % mod;
	}
} using namespace Maths;
namespace Loser {
	int n, m;
	vector<int> g[500010];
	int tim, dfn[500010], low[500010], ins[500010], sc; vector<int> scc[500010]; stack<int> st;
	void dfs(int u, int fa) {
		dfn[u] = low[u] = ++tim; ins[u] = 1; st.push(u);
		for (auto v: g[u]) {
			if (!dfn[v]) {
				dfs(v, u);
				low[u] = min(low[u], low[v]);
			} else if (ins[v]) low[u] = min(low[u], dfn[v]);
		}
		if (low[u] == dfn[u]) {
			++sc;
			while (st.top() != u) scc[sc].pb(st.top()), ins[st.top()] = 0, st.pop(); scc[sc].pb(u); ins[u] = 0; st.pop(); 
		}
	}
	void main() {
		cin >> n >> m;
		for (int i = 1, u, v; i <= m; i++) {
			cin >> u >> v; u++, v++; if (u != v) g[u].pb(v);
		}
		for (int i = 1; i <= n; i++) if (!dfn[i]) dfs(i, 0);
		cout << sc << '\n';
		for (int i = sc; i; i--) {
			cout << scc[i].size(); for (auto u: scc[i]) cout << ' ' << u; cout << '\n';
		}
	}
}
signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T = 1; while (T--) Loser::main(); return 0;
}

詳細信息

Test #1:

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

input:

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

output:

4
1 6
2 5 2
1 3
2 4 1

result:

wrong answer Integer 6 violates the range [0, 5]