QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#689569 | #7738. Equivalent Rewriting | i_love_qingyu# | WA | 0ms | 3680kb | C++20 | 1.0kb | 2024-10-30 17:46:25 | 2024-10-30 17:46:26 |
Judging History
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)