QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#767721 | #7738. Equivalent Rewriting | guangxuautumn | RE | 0ms | 0kb | C++14 | 1.3kb | 2024-11-20 21:54:17 | 2024-11-20 21:54:17 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+7;
int val[N];
bool vis[N];
void solve()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; ++i) vis[i] = false;
vector<vector<int>> b(n+1);
for (int i = 1; i <= n; ++i)
{
int p;
cin >> p;
while (p--)
{
int x;
cin >> x;
b[i].push_back(x);
}
}
for (int i = n; i > 1; ++i)
{
set<int> s;
int sz = b[i].size() + b[i-1].size();
for (auto v : b[i])
{
if (!vis[v]) s.insert(v);
else sz--;
}
for (auto v : b[i-1])
{
if (!vis[v]) s.insert(v);
else sz--;
}
if (s.size() == sz)
{
cout << "Yes\n";
for (int j = 1; j <= n; ++j)
{
if (j == i) cout << i-1 << " ";
else if (j == i-1) cout << i << " ";
else cout << j << " ";
}
cout << "\n";
return;
}
for (auto v : b[i]) vis[v] = true;
}
cout << "No\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
详细
Test #1:
score: 0
Runtime Error
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