QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#126474 | #906. 强连通分量 | 1234567890# | WA | 1ms | 31192kb | C++14 | 2.1kb | 2023-07-18 15:20:42 | 2023-07-18 15:20:45 |
Judging History
answer
/*
灏忓簾鐗╋紝杩欓兘涓嶄細 /cf
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define inf (ll)1e9
#define pii pair <ll, ll>
#define fr first
#define se second
const ll mod = 1e9 + 7;
char buf[1 << 21], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 18, stdin), p1 == p2) ? EOF : *p1++)
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar();
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
inline void write(ll x) {
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
inline ll quickmod(ll x, ll y) {
ll Ans = 1;
while(y) {
if(y & 1) Ans = (1ll * Ans * x) % mod;
x = (1ll * x * x) % mod;
y >>= 1;
}
return Ans;
}
inline void Add(ll &x, ll y) {
x += y;
if(x >= mod) x -= mod;
}
inline void Dec(ll &x, ll y) {
x -= y;
if(x < 0) x += mod;
}
inline ll add(ll x, ll y) {
x += y;
if(x >= mod) x -= mod;
return x;
}
inline ll dec(ll x, ll y) {
x -= y;
if(x < 0) x += mod;
return x;
}
ll n, m;
vector <ll> G[500005];
ll dfn[500005], low[500005], tot;
ll sta[500005], top;
ll col[500005], color;
inline void Tarjan(ll x) {
dfn[x] = low[x] = ++tot;
sta[++top] = x;
for(auto y : G[x]) {
if(!dfn[y]) {
Tarjan(y);
low[x] = min(low[x], low[y]);
}
else if(!col[y]) low[x] = min(low[x], dfn[y]);
}
if(dfn[x] == low[x]) {
col[x] = ++color;
while(sta[top] != x) col[sta[top--]] = color;
top--;
}
}
vector <ll> C[500005];
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
n = read(), m = read();
for(ll i = 1; i <= m; i++) {
ll u = read() + 1, v = read() + 1;
G[u].push_back(v);
}
for(ll i = 1; i <= n; i++) if(!dfn[i]) Tarjan(i);
for(ll i = 1; i <= n; i++) C[col[i]].push_back(i);
write(color), putchar('\n');
for(ll i = 1; i <= color; i++) {
write((ll)C[i].size()), putchar(' ');
for(auto j : C[i]) write(j - 1), putchar(' ');
putchar('\n');
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 31192kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
4 2 0 3 1 2 2 1 4 1 5
result:
wrong answer 5 is later than 2, but there is an edge (5, 2)