QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#644733 | #7738. Equivalent Rewriting | AkTtt | WA | 0ms | 3624kb | C++14 | 1.9kb | 2024-10-16 15:18:06 | 2024-10-16 15:18:06 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e5 + 10;
const LL INFF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f,mod = 998244353;
#define debug(x) cout<< "[debug]" #x << " = " << x <<endl
int n, m;
void solve()
{
cin >> n >> m;
vector<int> v[n + 1], id(m + 1);
vector<int> cnt(n + 1);
map<PII, int> ma;
for(int i = 1; i <= n; i++){
int len;
cin >> len;
for(int j = 1; j <= len; j++){
int x;
cin >> x;
if(!id[x])id[x] = i;
else{
if(!ma.count({id[x], i})){
v[id[x]].push_back(i);
ma[{id[x], i}] = 1;
cnt[i]++;
}
}
}
}
auto TopSort = [&](){
priority_queue<int, vector<int>, less<int>> q;
vector<int> d;
for(int i = 1; i <= n; i++){
if(!cnt[i]){
q.push(i);
}
}
while(q.size()){
auto t = q.top();
q.pop();
d.push_back(t);
for(auto k : v[t]){
cnt[k]--;
if(!cnt[k]){
q.push(k);
}
}
}
if(d.size() == n){
bool ok = false;
for(int i = 0; i < n; i++){
if((i + 1) != d[i]){
ok = true;
break;
}
}
if(ok){
cout << "Yes" << endl;
for(int i = 0; i < n; i++){
cout << d[i];
if(i != n - 1)cout << ' ';
}
cout << endl;
return ;
}
}
cout << "No" << endl;
};
TopSort();
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while(T--)
{
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3624kb
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 1 10 3 2 8 5 9 7 6 4
result:
wrong answer two transactions are not equivalent. (test case 1)