QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642913 | #7738. Equivalent Rewriting | KDream | RE | 0ms | 3528kb | C++20 | 1.7kb | 2024-10-15 17:00:31 | 2024-10-15 17:00:32 |
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(m + 5),edge(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;
for (int i = 1;i <= n;i ++)
{
if (!in[i])
{
q.push(i);
ans.push_back(i);
}
}
while (!q.empty())
{
auto u = q.front();
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 = 0;i < ans.size();i ++)
{
if ((i + 1) != ans[i])
{
flag = 0;
break;
}
}
if (flag)
{
cout << "No" << "\n";
}
else
{
cout << "Yes\n";
for (auto i:ans)
{
cout << i << " ";
}
cout << "\n";
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--)
{
Z();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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
Runtime Error
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