QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#679111 | #7738. Equivalent Rewriting | dyfhpu | RE | 0ms | 0kb | C++17 | 1.2kb | 2024-10-26 16:54:52 | 2024-10-26 16:54:54 |
answer
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <vector>
using namespace std;
void solve()
{
int n,m;cin>>n>>m;
int in[n+10];
int st[n+10],st2[n+10];
vector<int> v[n+10];
int x[n+10];
int ss[n+10][m+10];
for(int i=1;i<=n+10;i++) in[i]=0,st[i]=0,st2[i]=0;
for(int i=1;i<=n;i++) {
cin>>x[i];
for(int j=1;j<=x[i];j++) {
cin>>ss[i][j];
int y=ss[i][j];
st[y]=i;
}
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=x[i];j++) {
int y=ss[i][j];
//cout<<"st[y]="<<st[y]<<endl;
if(i!=st[y]) {
v[i].push_back(st[y]);
in[st[y]]++;
}
}
}
queue<int> q;
int cnt=0;
for(int i=n;i>=1;i--) {
if(in[i]==0) {
q.push(i);cnt++;
}
}
if(cnt<2) {
cout<<"No"<<endl;
return ;
}
queue<int> s;
while(q.size()) {
int t=q.front();
s.push(t);q.pop();
for(auto f:v[t]) {
in[f]--;
if(in[f]==0) {
q.push(f);
}
}
}
if(s.size()==n) {
cout<<"Yes"<<endl;
while(s.size()) {
cout<<s.front()<<' ';
s.pop();
}
cout<<endl;
}
else cout<<"No"<<endl;
return ;
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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