QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#638598 | #7738. Equivalent Rewriting | Alasco | WA | 3ms | 13596kb | C++14 | 2.3kb | 2024-10-13 16:20:16 | 2024-10-13 16:20:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;using ll=long long;using ld=long double;using ull=unsigned long long;
const ll M=998244353;const double eps=1e-10;const int inf=1e9+7;const ll INF=1e17;
int n,m,d[100005],vis[100005];
vector<int>c[100005];
set<int>st[100005];
vector<int>e[100005];
vector<int>ans;
void __(){
cin>>n>>m;
ans.clear();
for(int i=1;i<=m;i++){
c[i].clear();
}
for(int i=1;i<=n;i++){
e[i].clear();
st[i].clear();
d[i]=0;
vis[i]=0;
}
for(int i=1;i<=n;i++){
int x,y;cin>>x;
for(int j=1;j<=x;j++){
cin>>y;
c[y].push_back(i);
}
}
for(int i=1;i<=m;i++){
if(c[i].size()<=1)continue;
for(int j=1;j<c[i].size();j++){
int u=c[i][j-1],v=c[i][j];
if(st[u].find(v)!=st[u].end())continue;
st[u].insert(v);
e[u].push_back(v);
d[v]++;
}
}
for(int i=1;i<=n;i++){
sort(e[i].begin(),e[i].end(),greater<int>());
}
queue<int>q;
// for(int i=1;i<=n;i++){
// cout<<d[i]<<" ";
// }
// cout<<"\n";
for(int i=n;i>=1;i--){
if(d[i]==0){
vis[i]=1;
q.push(i);
}
}
while(!q.empty()){
int u=q.front();
q.pop();
ans.push_back(u);
for(auto v:e[u]){
if(vis[v]==1)continue;
d[v]--;
if(d[v]<=0){
vis[v]=1;
q.push(v);
}
}
}
// for(int i=1;i<=n;i++){
// cout<<vis[i]<<" ";
// }
// cout<<"\n";
// for(int i=1;i<=n;i++){
// cout<<"I"<<i<<" : ";
// for(auto b:e[i]){
// cout<<b<<" ";
// }
// cout<<"\n";
// }
bool fl=0;
for(int i=1;i<=n;i++){
if(vis[i]==0){
cout<<"No\n";return;
}
if(ans[i-1]!=i)fl=1;
}
if(fl==0){
cout<<"No\n";return;
}
cout<<"Yes\n";
assert(ans.size()==n);
for(int i=0;i<n;i++){
cout<<ans[i]<<" ";
}
cout<<"\n";
}
signed main(){
ios::sync_with_stdio(false),cin.tie(nullptr);
int _;cin>>_;while(_--)__();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13596kb
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: 3ms
memory: 13012kb
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)