QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#695444 | #7738. Equivalent Rewriting | six_ssp | WA | 0ms | 4108kb | C++23 | 1.3kb | 2024-10-31 20:02:59 | 2024-10-31 20:03:02 |
Judging History
answer
#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
priority_queue<int > q;
struct node{
int to,nxt;
}e[2000006];
int cnt,head[100005];
void add(int x,int y)
{
e[++cnt].to=y;
e[cnt].nxt=head[x];
head[x]=cnt;
}
int bu[100005],rd[100005];
int vis[100005],cha[100005];
int main()
{
int T;
cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
int p;
cin>>p;
for(int j=1;j<=p;j++)
{
cin>>cha[j];
if(bu[cha[j]]==0)
bu[cha[j]]=i;
else if((vis[cha[j]]==0) && (bu[cha[j]]!=0))
{
add(bu[cha[j]],i);
rd[i]++;
bu[cha[j]]=i;
vis[cha[j]]=1;
}
}
for(int j=1;j<=p;j++)
vis[cha[j]]=0;
}
//for(int i=1;i<=n;i++)
// cout<<rd[i]<<" ";
int pd=0;
for(int i=1;i<=n;i++)
if(rd[i]==0)
q.push(i);
int ans[100005],cnt=0;
while(!q.empty())
{
int x=q.top();
q.pop();
ans[++cnt]=x;
if(cnt!=x) pd=1;
for(int i=head[x];i;i=e[i].nxt)
{
int y=e[i].to;
rd[y]--;
if(rd[y]==0)
q.push(y);
}
}
if(pd==0) cout<<"No";
if(pd==1)
{
cout<<"Yes"<<endl;
for(int i=1;i<=cnt;i++)
cout<<ans[i]<<" ";
}
cout<<endl;
for(int i=1;i<=n;i++)
bu[i]=rd[i]=0;
cnt=0;
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4040kb
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 3 1 2 No No
result:
ok OK. (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 4108kb
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)