为什么会WA
查看原帖
为什么会WA
115359
phigy楼主2021/3/13 14:34

非void的函数不return 0会RE这我知道。

但是为什么这份代码中的add函数不return会WA掉?

#include <iostream>

using namespace std;

struct edge
{
    int next,to;
}e[5000000];
int cnt,head[5000000];
int add(int u,int v)
{
    cnt++;
    e[cnt].to=v;
    e[cnt].next=head[u];
    head[u]=cnt;
    return 0;
}

int n,m;

int dfn[5000000],low[5000000],scc[5000000],vis[5000000];
int now,col;
int sta[5000000],len;
int tarjan(int x)
{
    now++;
    dfn[x]=low[x]=now;
    vis[x]=1;
    len++;
    sta[len]=x;
    for(int i=head[x];i;i=e[i].next)
    {
        int v=e[i].to;
        if(dfn[v]==0)
        {
            tarjan(v);
            low[x]=min(low[x],low[v]);
        }
        if(vis[v]==1)
        {
            low[x]=min(low[x],dfn[v]);
        }
    }
    if(dfn[x]==low[x])
    {
        col++;
        while(sta[len]!=x)
        {
            scc[sta[len]]=col;
            vis[sta[len]]=0;
            len--;
        }
        scc[sta[len]]=col;
        vis[sta[len]]=0;
        len--;
    }
    return 0;
}

signed main()
{
    int i,j,k;
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        int a,b,x,y;
        cin>>a>>x>>b>>y;
        if(x==0&&y==0)
        {
            add(a+n,b);
            add(b+n,a);
        }
        if(x==1&&y==0)
        {
            add(a,b);
            add(b+n,a+n);
        }
        if(x==0&&y==1)
        {
            add(a+n,b+n);
            add(b,a);
        }
        if(x==1&&y==1)
        {
            add(a,b+n);
            add(b,a+n);
        }
    }
    for(i=1;i<=2*n;i++)
    {
        if(dfn[i]==0)
        {
            tarjan(i);
        }
    }
    for(i=1;i<=n;i++)
    {
        if(scc[i]==scc[i+n])
        {
            cout<<"IMPOSSIBLE";
            return 0;
        }
    }
    cout<<"POSSIBLE"<<endl;
    for(i=1;i<=n;i++)
    {
        if(scc[i]>scc[i+n])cout<<"1 ";
        else cout<<"0 ";
    }
    return 0;
}

2021/3/13 14:34
加载中...