This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <bitset>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < (int) b; i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
#define f first
#define s second
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};
void setIO(string nome) {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen ((nome + ".in").c_str(), "r", stdin);
freopen ((nome + ".out").c_str(), "w", stdout);
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vvi q (m);
F0R (i, m) {
int foo;
cin >> foo;
F0R (j, foo) {
int bar;
cin >> bar;
q[i].eb(bar);
}
}
int ans = -1;
bitset<61> Get;
F0R (mask, 1 << m) {
Get.reset();
F0R (i, m) {
if ((mask >> i) & 1) {
GO (to, q[i]) {
Get.flip(to);
}
}
}
if ((int) Get.count() == n) {
if (ans == -1 || __builtin_popcount(mask) < __builtin_popcount(ans)) ans = mask;
else if (__builtin_popcount(mask) == __builtin_popcount(ans)) {
F0R (i, m) {
int A = ((ans >> i) & 1);
int B = ((mask >> i) & 1);
if (A && !B) {
break;
}
if (B && !A) {
ans = mask;
break;
}
}
}
}
}
cout << __builtin_popcount(ans) << '\n';
F0R (i, m) {
if ((ans >> i) & 1) cout << i + 1 << ' ';
}
cout << '\n';
return 0;
}
Compilation message (stderr)
norela.cpp: In function 'void setIO(std::__cxx11::string)':
norela.cpp:39:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen ((nome + ".in").c_str(), "r", stdin);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
norela.cpp:40:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen ((nome + ".out").c_str(), "w", stdout);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |