QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#689569#7738. Equivalent Rewritingi_love_qingyu#WA 0ms3680kbC++201.0kb2024-10-30 17:46:252024-10-30 17:46:26

Judging History

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

  • [2024-10-30 17:46:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3680kb
  • [2024-10-30 17:46:25]
  • 提交

answer

#include <iostream>
#include <cstdio>
using namespace std;
int book[100005],last[100005],ans[100005];
int find(int x){
    return x==book[x]?x:(book[x]=find(book[x]));
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,m,p=0;
        cin>>m>>n;
        for(int i=1;i<=n;i++)last[i]=0;
        for(int i=1;i<=m;i++)book[i]=i,ans[i]=i;
        for(int i=1;i<=m;i++){
            int k,a;
            cin>>k;
            for(int j=1;j<=k;j++){
                cin>>a;
                if(last[a]){
                    int x=find(book[last[a]]);
                    book[i]=book[x];
                }else
                    last[a]=i;
            }
        }
        for(int i=2;i<=m;i++)
            if(book[i]!=book[i-1]){
                swap(ans[i],ans[i-1]);
                p=1;
            }
        if(p){
            cout<<"Yes"<<endl;
            for(int i=1;i<=m;i++)
                cout<<ans[i]<<" ";
            cout<<endl;
        }
        else cout<<"No"<<endl;
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

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:

Yes
1 3 2 
No
No

result:

ok OK. (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3680kb

input:

1
10 5
2 2 4
4 1 3 4 2
1 2
3 2 1 4
4 5 2 4 3
3 2 5 4
3 5 4 2
3 1 3 2
5 1 4 2 3 5
1 4

output:

No

result:

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