0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 18:11:59 +00:00

P8252 [NOI Online 2022 提高组] 讨论

https://www.luogu.com.cn/record/102566109
This commit is contained in:
Baoshuo Ren 2023-02-19 22:20:45 +08:00
parent 3266ee94cc
commit f52f5f3a6c
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

90
Luogu/P8252/P8252.cpp Normal file
View File

@ -0,0 +1,90 @@
#include <iostream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <unordered_set>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
struct node {
int id;
std::vector<int> v;
node(const int &_id = 0, const int &_sz = 0)
: id(_id), v(_sz) {}
};
void solve() {
int n;
cin >> n;
std::vector<node> v;
std::vector<int> t(n, -1);
for (int i = 1, k; i <= n; i++) {
cin >> k;
v.emplace_back(node(i, k));
for (int &x : v.back().v) cin >> x, x--;
}
std::sort(v.begin(), v.end(), [&](const node &a, const node &b) -> bool {
return a.v.size() > b.v.size();
});
for (int i = 0; i < n; i++) {
std::unordered_set<int> set;
for (int x : v[i].v) {
if (t[x] != -1) set.emplace(t[x]);
}
if (set.size() == 1) {
int id = *set.begin();
for (int x : v[i].v) {
if (t[x] != id) {
cout << "YES" << endl
<< v[i].id << ' ' << v[id].id << endl;
return;
}
}
} else if (set.size() > 1) {
int id = *set.begin();
for (int x : set) {
if (v[x].v.size() < v[id].v.size()) id = x;
}
cout << "YES" << endl
<< v[i].id << ' ' << v[id].id << endl;
return;
}
for (int x : v[i].v) {
t[x] = i;
}
}
cout << "NO" << endl;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) solve();
return 0;
}