QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#92326 | #906. 强连通分量 | zhaohaikun# | WA | 1ms | 13764kb | C++14 | 1.4kb | 2023-03-30 15:55:26 | 2023-03-30 15:55:30 |
Judging History
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;
}
詳細信息
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)