-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.cpp
More file actions
55 lines (52 loc) · 1.18 KB
/
A.cpp
File metadata and controls
55 lines (52 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "bits/stdc++.h"
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int>> v(m);
map<int, int> mp;
vector<int> ans(m);
for (int i = 0; i < m; i++) {
int k_i;
cin >> k_i;
v[i].resize(k_i);
for (int j = 0; j < k_i; j++) {
cin >> v[i][j];
}
if (k_i == 1) {
mp[v[i][0]]++;
}
}
for (int i = 0; i < m; i++) {
if (v[i].size() > 1) {
ans[i] = 0;
for (auto j: v[i])
if (mp[j] + 1 <= (m + 1) / 2) {
++mp[j], ans[i] = j;
break;
}
if (!ans[i]) {
cout << "NO\n";
return;
}
} else
ans[i] = v[i][0];
}
map<int, int> chk;
for (auto i: ans) {
chk[i]++;
if (chk[i] > (m + 1) / 2) {
cout << "NO\n" << endl;
return;
}
}
cout << "YES" << endl;
for (auto i: ans)cout << i << ' ';
cout << endl;
}
signed main() {
int T;
cin >> T;
while (T--)
solve();
}