QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649085 | #906. 强连通分量 | lngsctrer | WA | 2ms | 8516kb | C++14 | 1.3kb | 2024-10-17 21:33:33 | 2024-10-17 21:33:34 |
Judging History
answer
#include<bits/stdc++.h>
using i64 = long long;
const int N = 200010;
int read(){
int x = 0, f = 1, c = getchar();
while(!isdigit(c)){
if(c == '-') f = -1;
c = getchar();
}
while(isdigit(c)){
x = x * 10 + (c ^ 48);
c = getchar();
}
return x * f;
}
int n, m;
std::vector<int> E[N];
int low[N], dfn[N], vis[N], dfncnt, st[N], tp;
std::vector<std::vector<int> > ans;
void tarjan(int x, int f){
low[x] = dfn[x] = ++ dfncnt, vis[x] = 1;
st[++ tp] = x;
for(int to : E[x]){
if(!dfn[to]){
tarjan(to, x);
low[x] = std::min(low[x], low[to]);
}else if(vis[to]) low[x] = std::min(low[x], dfn[to]);
}
if(dfn[x] == low[x]){
std::vector<int> tmp;
while(st[tp] != x && tp){
tmp.push_back(st[tp]);
vis[st[tp]] = 0;
tp --;
}
tmp.push_back(st[tp]);
vis[st[tp]] = 0;
tp --;
ans.push_back(tmp);
}
}
void solve(){
n = read(), m = read();
for(int i = 1; i <= m;i ++){
int x = read(), y = read();
E[x].push_back(y);
}
for(int i = 0; i < n; i ++){
if(!dfn[i]) tarjan(i, i);
}
int col = ans.size();
std::cout << col << '\n';
for(std::vector<int> inp : ans){
std::cout << inp.size() << " ";
for(int x : inp){
std::cout << x << " ";
}
std::cout << '\n';
}
}
signed main(){
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 8516kb
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)