-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path12348.alt.cpp
More file actions
34 lines (29 loc) · 772 Bytes
/
12348.alt.cpp
File metadata and controls
34 lines (29 loc) · 772 Bytes
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
#include <string>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstring>
using namespace std;
int in, t, n, m, sets[120];
string line;
int main() {
for (cin >> t; t--;) {
cin >> n >> m;
getline(cin, line);
memset(sets, 0, sizeof(sets));
for (int i = 0; i < m; i++) {
getline(cin, line);
stringstream stream(line);
while (stream >> in) sets[i] |= 1 << (in - 1);
}
bool solved = false;
for (int i = 1; i < (2 << (n - 1)) and not solved; i++) {
bool valid = true;
for (int j = 0; j < m and valid; j++)
valid &= ((i & sets[j]) != 0 and (i & sets[j]) != sets[j]) or __builtin_popcount(sets[j]) == 1;
solved |= valid;
}
putchar((solved) ? 'Y' : 'N');
}
return 0;
}