QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#275330 | #7738. Equivalent Rewriting | DateTree | WA | 0ms | 3804kb | C++17 | 1.4kb | 2023-12-04 16:48:40 | 2023-12-04 16:48:40 |
Judging History
answer
#include <bits/stdc++.h>
bool chk(std::vector<int>& a) {
int n = a.size();
for (int i = 0; i < n; ++i)
if (a[i] != i + 1)
return 0;
return 1;
}
int main() {
//freopen("in", "r", stdin);
int ttt;
std::cin >> ttt;
while (ttt--) {
int n, m;
std::cin >> n >> m;
std::vector<int> b(m + 1), ind(n + 1);
std::vector ver(n + 1, std::vector<int>(0));
for (int i = 1; i <= n; ++i) {
int p, x;
std::cin >> p;
while (p--) {
std::cin >> x;
if (b[x]) {
ver[b[x]].push_back(i);
++ind[i];
}
b[x] = i;
}
}
std::queue<int> q;
std::vector<int> ans;
for (int i = n; i >= 1; --i) {
if (!ind[i]) {
q.push(i);
}
}
while (!q.empty()) {
int u = q.front(); q.pop();
ans.emplace_back(u);
for (auto &v: ver[u]) {
--ind[v];
if (!ind[v])
q.push(v);
}
}
if (chk(ans)) {
std::cout << "No\n";
continue;
}
std::cout << "Yes\n";
for (int i = 0; i < n; ++i)
std::cout << ans[i] << " \n"[i == n - 1];
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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: 3804kb
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)