QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640620 | #7738. Equivalent Rewriting | Doubeecat | WA | 1ms | 3620kb | C++20 | 1.7kb | 2024-10-14 14:48:48 | 2024-10-14 14:48:48 |
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) cout << 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: 100
Accepted
time: 1ms
memory: 3620kb
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: 1ms
memory: 3588kb
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)