QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411009#8150. XOR SumsycqwqWA 0ms46832kbC++142.8kb2024-05-14 20:08:042024-05-14 20:08:05

Judging History

你现在查看的是最新测评结果

  • [2024-05-14 20:08:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:46832kb
  • [2024-05-14 20:08:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
int _;
int n,m,a[maxn];
vector<int> e[maxn],t[maxn],g[maxn];
int x[maxn],y[maxn],fa[maxn],col[maxn],f[maxn],d[maxn],dp[maxn];
int getfa(int x)
{
    return x==fa[x]?x:fa[x]=getfa(fa[x]);
}

int main()
{   
    // freopen("in.in","r",stdin);
    // freopen("out.out","w",stdout);
    cin>>_;
    while(_--)
    {
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            e[i].clear(),t[i].clear(),g[i].clear(),f[i]=dp[i]=0,d[i]=0;;
        for(int i=1;i<=m;i++)
        {
            cin>>x[i]>>y[i];
            e[x[i]].push_back(y[i]);
        }
        for(int i=1;i<=n;i++)
            fa[i]=i;
        for(int i=1;i<=n;i++)
        {
            int t=0;
            for(auto v:e[i])
            {
                if(!t)
                    t=getfa(v);
                fa[getfa(v)]=t;
            }
        }
        int pd=0;
        for(int i=1;i<=m;i++)
            if(getfa(x[i])==getfa(y[i]))
                pd=1;
        if(pd)
        {
            cout<<"No"<<'\n';
            continue;
        }
        int co=0;
        memset(d,0,sizeof d);
        for(int i=1;i<=n;i++)
            if(getfa(i)==i)
                col[i]=++co;
        for(int i=1;i<=n;i++)
            col[i]=col[getfa(i)],t[col[i]].push_back(i);
        for(int i=1;i<=m;i++)
            g[col[x[i]]].push_back(col[y[i]]),++d[col[y[i]]];
        queue<int> q;
        q.push(col[1]);
        while(!q.empty())
        {
            int x=q.front();
            q.pop();
            for(auto v:g[x])
            {
                --d[v];
                if(d[v]==0)
                    q.push(v);
            }
        }
        for(int i=1;i<=co;i++)
            if(d[i])
                pd=1;
        if(pd)
        {
            cout<<"No"<<'\n';
            continue;
        }
        for(int i=1;i<=co;i++)
            g[i].clear();
        for(int i=1;i<=m;i++)
            g[col[y[i]]].push_back(col[x[i]]),++d[col[x[i]]]; 
        q.push(col[n]);
        while(!q.empty())
        {
            int x=q.front();
            q.pop();
            // cerr<<x<<'\n';
            int ma=0;
            for(auto p:t[x])
            {
                for(auto v:e[p])
                    dp[p]=f[col[v]];
                ma=max(ma,dp[p]+1);
                // cerr<<p<
            }
            // cerr<<x<<' '<<ma<<'\n';
            f[x]=ma;
            for(auto p:t[x])
                a[p]=ma-dp[p];
            for(auto v:g[x])
            {
                --d[v];
                if(d[v]==0)
                    q.push(v);
            }
        }
        cout<<"Yes\n";
        for(int i=1;i<=n;i++)
            cout<<a[i]<<' ';
        cout<<'\n';
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 46832kb

input:

6 2 3

output:

No
No
No
No
No
No

result:

wrong output format Expected integer, but "No" found