已AC,但求助
查看原帖
已AC,但求助
632955
伊地知虹夏楼主2023/4/10 23:11
#include<bits/stdc++.h> 
#define int long long
using namespace std;
const int N = 5e5+5,M = 6e6+5;
struct node{
	int nxt,to;
}e[M];
int tot = 1,head[N],cnt,col[N];
void add(int x,int y){
	e[++tot] = (node){head[x],y};head[x] = tot;
}
int n,m,low[N],dfn[N];
int stk[N],top;
bool ans[N];
vector<int> K[N];
void tarjan(int x,int edges){
	low[x] = dfn[x] = ++tot;
	for(int i = head[x];i;i = e[i].nxt){
		int y = e[i].to;
		if(!dfn[y]){
			tarjan(y,i);
			low[x] = min(low[x], low[y]);
			if(low[y] > dfn[x]) ans[i] = ans[i^1] = 1;
		}
		else if(i != (edges^1)) low[x] = min(low[x], dfn[y]);
	}
	return ;
}
void dfs(int x){
    col[x] = cnt;
    K[cnt].push_back(x);
    for (int i = head[x]; i; i = e[i].nxt)
    {
        int y = e[i].to;
        if (col[y] || ans[i])
            continue;
        dfs(y);
    }
    return;
}
signed main()
{
    cin >> n >> m;
    for(int i = 1;i <= m;i ++){
		int a,b;
		cin >> a >> b;
        if(a == b)
            continue;//
        add(a, b);
        add(b,a);
	}
	for(int i = 1;i <= n;i ++)
		if(!dfn[i])
			tarjan(i,0);
    for (int i = 1;i <= n;i ++)
        if(!col[i])
            ++cnt, dfs(i);
    cout << cnt << '\n';
    for(int i = 1;i <= cnt;i ++){
	    cout << K[i].size() << ' ';
	    for(int j = 0;j < K[i].size();j ++)
	        cout << K[i][j] << ' ';
	    cout << '\n';
	}
	return 0;
}

开了 long long 后才能过,为啥?

2023/4/10 23:11
加载中...