QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#243538 | #7738. Equivalent Rewriting | HpSuda# | WA | 0ms | 3612kb | C++14 | 1.5kb | 2023-11-08 14:00:42 | 2023-11-08 14:00:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<int> pos(m + 1);
vector<vector<int>> g(n + 1);
vector<int> in(n + 1), p(n + 1);
for (int i = 1; i <= n; i++) {
cin >> p[i];
for (int j = 0; j < p[i]; j++) {
int x;
cin >> x;
if (pos[x]) {
g[pos[x]].emplace_back(i);
in[i]++;
}
pos[x] = i;
}
}
priority_queue<int> que;
for (int i = 1; i <= n; i++) {
if (!in[i]) {
que.emplace(i);
}
}
vector<int> ans;
while (!que.empty()) {
int k = que.top();
que.pop();
ans.emplace_back(k);
for (auto v: g[k]) {
in[v]--;
if (!in[v]) {
que.emplace(v);
}
}
}
if (ans.size() != n) {
cout << "No\n";
return;
}
int ok = 0;
for (int i = 0; i < n; i++) {
if (ans[i] != i + 1) {
ok = 1;
break;
}
}
if (!ok) {
cout << "No\n";
return;
}
cout << "Yes\n";
for (int i = 0; i < n; i++) {
cout << ans[i] << " \n"[i + 1 == n];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _ = 1;
cin >> _;
for (; _; _--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 3612kb
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)