QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#267372 | #7738. Equivalent Rewriting | tonylin1026 | WA | 0ms | 3840kb | C++23 | 1.4kb | 2023-11-27 10:43:43 | 2023-11-27 10:43:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<int> now(m + 1), ind(n + 1);
vector<set<int, greater<int>>> to(n + 1);
for (int i = 1; i <= n; i++) {
int p;
cin >> p;
for (int j = 1; j <= p; j++) {
int x;
cin >> x;
if (now[x] && to[now[x]].find(i) == to[now[x]].end()) {
to[now[x]].insert(i);
ind[i]++;
}
now[x] = i;
}
}
vector<int> ans;
queue<int> q;
for (int i = n; i >= 1; i--) {
if (ind[i] == 0) {
q.push(i);
}
}
while (!q.empty()) {
int now = q.front();
q.pop();
ans.push_back(now);
for (auto it : to[now]) {
ind[it]--;
if (ind[it] == 0) {
q.push(it);
}
}
}
bool check = 0;
for (int i = 0; i < n; i++) {
if (ans[i] != i + 1) {
check = 1;
break;
}
}
if (check) {
cout << "Yes\n";
for (int i = 0; i < n; i++) {
cout << ans[i] << " \n"[i + 1 == n];
}
} else
cout << "No\n";
return;
}
int main() {
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: 0ms
memory: 3604kb
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: 3840kb
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)