QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#670901 | #906. 强连通分量 | yhddd | WA | 1ms | 5804kb | C++20 | 1.6kb | 2024-10-24 08:26:13 | 2024-10-24 08:26:13 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=500010;
const int inf=1e18;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
bool Mbe;
int n,m;
int head[maxn],tot=1;
struct nd{
int nxt,to;
}e[maxn];
void add(int u,int v){e[++tot]={head[u],v};head[u]=tot;}
int dfn[maxn],lw[maxn],idx;
vector<int> id[maxn];
int scc[maxn],scct;
int st[maxn],tp;
void tar(int u){
st[++tp]=u,dfn[u]=lw[u]=++idx;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(!dfn[v]){
tar(v);
lw[u]=min(lw[u],lw[v]);
}
else if(!scc[v])lw[u]=min(lw[u],dfn[v]);
}
if(dfn[u]==lw[u]){
id[++scct].pb(st[tp]),scc[st[tp]]=scct;
while(st[tp--]!=u)id[scct].pb(st[tp]),scc[st[tp]]=scct;
}
}
void work(){
n=read();m=read();
for(int i=1;i<=m;i++){
int u=read(),v=read();
add(u+1,v+1);
}
for(int i=1;i<=n;i++)if(!dfn[i])tar(i);
printf("%lld\n",scct);
for(int i=1;i<=scct;i++){
sort(id[i].begin(),id[i].end());
printf("%lld ",id[i].size());
for(int j:id[i])printf("%lld ",j-1);puts("");
}
}
// \
444
bool Med;
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
T=1;
while(T--)work();
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5804kb
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)