QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#246647#7738. Equivalent Rewritingqwq7WA 0ms3528kbC++202.0kb2023-11-10 23:43:362023-11-10 23:43:37

Judging History

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

  • [2023-11-10 23:43:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3528kb
  • [2023-11-10 23:43:36]
  • 提交

answer

// 哎 签到低手
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define PII pair<int,int>
#define PDI pair<double,int>
#define db double
#define all(x) (x).begin(),(x).end()
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
const int mod = 1e9+7;

void solve(){
    int n,m;cin>>n>>m;
    vector<int>v[n+1],pre(m+1),last(m+1);
    vector<int>g[n+1],deg(n+1);
    for(int i=1;i<=n;i++){
        int x;cin>>x;
        while(x--){
            int now;cin>>now;
            v[i].push_back(now);
            last[now]=i;
        }
    }
    for(int i=1;i<=n;i++){
        for(auto j:v[i]){
            g[i].push_back(last[j]);
            deg[last[j]]++;
        }
    }
    vector<int>q;
    for(int i=1;i<=n;i++){
        if(!deg[i])q.push_back(i);
    }
    vector<int>ans(n+1);
    for(int i=1;i<=n;i++)ans[i]=i;
    while(q.size()){
        if(q.size()>=2){
            cout<<"Yes"<<endl;
            int mx=max(q[0],q[1]),mn=min(q[0],q[1]);
            for(int j=1;j<=n;j++){
                if(mx==j)continue;
                if(j==1){
                    if(j==mn){
                        cout<<mx<<' '<<mn;
                    }else{
                        cout<<j;
                    }
                }
                else {
                    if(j==mn){
                        cout<<' '<<mx<<' '<<mn;
                    }else{
                        cout<<' '<<j;
                    }
                }
            }cout<<endl;
            return;
        }
        vector<int>nq;
        while(q.size()){
            auto u=q.back();q.pop_back();
            for(auto v:g[u]){
                deg[v]--;
                if(deg[v]==0){
                    nq.push_back(0);
                }
            }
        }
        q=nq;
    }
    cout<<"No"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int t=1;cin>>t;
    while(t--)solve();
}

詳細信息

Test #1:

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

input:

3
3 6
3 3 1 5
2 5 3
2 2 6
2 3
3 1 3 2
2 3 1
1 3
2 2 1

output:

No
No
No

result:

wrong answer jury found an answer but participant did not (test case 1)