QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642988 | #7738. Equivalent Rewriting | KDream | WA | 0ms | 3624kb | C++20 | 1.8kb | 2024-10-15 17:32:34 | 2024-10-15 17:32:35 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void Z()
{
int n, m;
cin >> n >> m;
int y = max(n, m);
vector<vector<int>> a(y + 5), edge(y + 5);
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
while (x--)
{
int b;
cin >> b;
a[b].push_back(i);
}
}
vector<int> in(y + 5);
for (int i = 1; i <= m; i++)
{
if (a[i].size() == 0)
continue;
int go = a[i].back();
for (auto v : a[i])
{
if (v == go)
continue;
edge[v].push_back(go);
in[go]++;
}
}
queue<int> q;
vector<int> ans;
ans.push_back(0);
for (int i = n; i >= 1; i--)
{
if (!in[i])
{
q.push(i);
}
}
while (!q.empty())
{
auto u = q.front();
q.pop();
ans.push_back(u);
if (edge[u].size())
sort(edge[u].begin(), edge[u].end(), greater<>());
for (auto v : edge[u])
{
in[v]--;
if (!in[v])
{
q.push(v);
}
}
}
bool flag = 1;
for (int i = 1; i <= ans.size(); i++)
{
if (i != ans[i])
{
flag = 0;
break;
}
}
if (flag)
{
cout << "No";
}
else
{
cout << "Yes\n";
for (int i = 1; i <= n; i++)
{
cout << ans[i] << " ";
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--)
{
Z();
if (t)
{
cout << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
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 Yes 1 2 Yes 1
result:
wrong answer two transactions are same. (test case 2)