QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640618 | #7738. Equivalent Rewriting | Doubeecat | WA | 1ms | 3820kb | C++20 | 1.7kb | 2024-10-14 14:48:18 | 2024-10-14 14:48:19 |
Judging History
answer
/*
Undo the destiny.
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
const int N = 1e5 + 10;
vector <int> G[N];
int n,m,lst[N],deg[N];
void solve() {
cin >> n >> m;
for (int i = 1;i <= m;++i) lst[i] = 0;
for (int i = 1;i <= n;++i) G[i].clear(),deg[i] = 0;
int cnt;cin >> cnt;
for (int i = 1;i <= cnt;++i) {
int x;cin >> x;lst[x] = 1;
}
set <pii> edg;
for (int i = 2;i <= n;++i) {
cin >> cnt;
for (int j = 1;j <= cnt;++j) {
int x;cin >> x;
if(lst[x]) edg.insert(mp(lst[x],i));
lst[x] = i;
}
}
for (auto [x,y] : edg) {
G[x].push_back(y);++deg[y];
//cout << "e:" << x << " " << y <<"\n";
}
int tot = 0;
queue <int> q;
for (int i = 2;i <= n;++i) {
if (!deg[i] && i != 1) {
++tot;
q.push(i);
}
}
++tot;q.push(1);
if (tot > 1) {
cout << "Yes\n";
vector <int> ans;
while (!q.empty()) {
int x = q.front();q.pop();
ans.push_back(x);
for (auto y : G[x]) {
if (!--deg[y]) {
q.push(y);
}
}
}
for(auto x : ans) printf("%d ",x);
cout << "\n";
} else {
cout << "No\n";
}
}
signed main() {
ios::sync_with_stdio(false);
//cin.tie(0);//cout.tie(0);
int T;cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3820kb
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 No No 3 1 2
result:
wrong output format Expected integer, but "No" found (test case 1)