QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642930 | #7738. Equivalent Rewriting | KDream | WA | 0ms | 3808kb | C++20 | 1.9kb | 2024-10-15 17:08:26 | 2024-10-15 17:08:27 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void Z()
{
int n, m;
cin >> n >> m;
vector<vector<int>> a(max(n, m) + 5), edge(max(n, m) + 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(max(n, m) + 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 = 1; i <= n; i++)
{
if (!in[i])
{
q.push(i);
ans.push_back(i);
}
}
while (!q.empty())
{
auto u = q.front();
if (edge[u].size())
sort(edge[u].begin(), edge[u].end(), greater<>());
q.pop();
for (auto v : edge[u])
{
in[v]--;
if (!in[v])
{
q.push(v);
ans.push_back(v);
}
}
}
bool flag = 1;
for (int i = 1; i <= n; 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: 100
Accepted
time: 0ms
memory: 3808kb
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 1 3 2 No No
result:
ok OK. (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3808kb
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)