QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#670068 | #7738. Equivalent Rewriting | Nyans | WA | 2ms | 8412kb | C++14 | 1.6kb | 2024-10-23 20:22:41 | 2024-10-23 20:22:41 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
int n, m, deg[100010];
std::vector<int> pos[100010], G[100010];
void solve() {
std::cin >> n >> m;
for (int i = 0; i <= n; ++i) {
pos[i].clear();
G[i].clear();
deg[i] = 0;
}
for (int i = 1; i <= n; ++i) {
int p; std::cin >> p;
for (int j = 1; j <= p; ++j) {
int x; std::cin >> x;
pos[x].push_back(i);
}
}
for (int i = 1; i <= n; ++i) {
if (pos[i].size() <= 1) {
continue;
}
int x = pos[i].back();
for (auto v : pos[i]) {
if (v != x) {
G[v].push_back(x);
++deg[x];
}
}
}
std::queue<int> Q;
std::vector<int> ans;
for (int i = 1; i <= n; ++i) {
if (deg[i] == 0) {
Q.push(i);
}
}
while (!Q.empty()) {
int u = Q.front(); Q.pop();
ans.push_back(u);
for (auto v : G[u]) {
if (--deg[v] == 0) {
Q.push(v);
}
}
}
bool ok = 0;
for (int i = 0; i < n; ++i) {
if (ans[i] != i + 1) {
ok = 1;
break;
}
}
if (ok) {
std::cout << "Yes\n";
for (auto v : ans) {
std::cout << v << " ";
}
std::cout << "\n";
} else {
std::cout << "No\n";
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T; std::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: 8412kb
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 1 3 2 No No
result:
ok OK. (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 8140kb
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)