QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265356 | #7738. Equivalent Rewriting | ucup-team059 | WA | 0ms | 3632kb | C++20 | 1.3kb | 2023-11-25 18:00:30 | 2023-11-25 18:00:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
using i64 = long long;
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int, int>;
const int N = 1e4 + 5;
void solve() {
int n, m;
cin >> n >> m;
vi lst(m + 1), inDeg(n + 1);
vector<vi> e(n + 1);
for (int i = 1, p; i <= n; i++) {
cin >> p;
for (int x; p; p--) {
cin >> x;
if (lst[x] != 0 and lst[x] != i ) {
inDeg[i]++;
e[lst[x]].push_back(i);
}
lst[x] = i;
}
}
priority_queue<int> q;
for (int i = 1; i <= n; i++)
if (inDeg[i] == 0) q.push(i);
vi res;
for (int u; not q.empty();) {
u = q.top(), q.pop();
res.push_back(u);
for (auto v: e[u]) {
if (--inDeg[v] == 0) res.push_back(v);
}
}
if (res.size() != n or is_sorted(res.begin(), res.end())) {
cout << "No\n";
} else {
cout << "Yes\n";
for (auto i: res)
cout << i << " \n"[i == res.back()];
}
return;
}
i32 main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
i32 TC;
for (cin >> TC; TC; TC--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
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: 3620kb
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)