QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#262991 | #7738. Equivalent Rewriting | ucup-team093# | WA | 0ms | 3816kb | C++17 | 1.3kb | 2023-11-24 13:55:15 | 2023-11-24 13:55:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int> > g(n), a(m);
vector<int> deg(n);
for(int i = 0, p; i < n; i ++) {
cin >> p;
for(int j = 0, x; j < p; j ++) {
cin >> x;
a[x - 1].push_back(i);
}
}
for(int i = 0; i < m; i ++) {
if(a[i].size() > 1) {
for(int j = 0; j + 1 < a[i].size(); j ++)
g[a[i][j]].push_back(a[i].back());
deg[a[i].back()] ++;
}
}
priority_queue<int> q;
for(int i = 0; i < n; i ++)
if(deg[i] == 0)
q.push(i);
vector<int> ans;
while(q.size()) {
int u = q.top();
q.pop();
ans.push_back(u);
for(auto v : g[u]) {
if(--deg[v] == 0)
q.push(v);
}
}
for(int i = 0; i < n; i ++)
if(ans[i] != i) {
cout << "Yes\n";
for(auto x : ans)
cout << x + 1 << " \n"[x == ans.back()];
return;
}
cout << "No\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while(T --)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3752kb
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: 3816kb
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:
Yes 8 7 10 9 6 5 4 3 2 1
result:
wrong answer two transactions are not equivalent. (test case 1)