#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<bitset<105>> eq(n);
for (int i = 0; i < n; i++) {
eq[i][104] = 1; // rhs = 1 (tüm kartlar başlangıçta ters)
}
for (int i = 0; i < m; i++) {
int q;
cin >> q;
for (int j = 0; j < q; j++) {
int a;
cin >> a;
a--;
eq[a][i] = 1; // i. büyü a. kartı etkiler
}
}
vector<int> used;
vector<bool> pivot_found(n, false);
// Gauss eliminasyonu
for (int col = 0; col < m; col++) {
int pivot = -1;
for (int row = 0; row < n; row++) {
if (eq[row][col] && !pivot_found[row]) {
pivot = row;
pivot_found[row] = true;
break;
}
}
if (pivot == -1) continue;
used.push_back(col + 1);
// Diğer satırlardan bu pivotu elimine et
for (int row = 0; row < n; row++) {
if (row != pivot && eq[row][col]) {
eq[row] ^= eq[pivot];
}
}
}
// Çözümü kontrol et
bool possible = true;
for (int i = 0; i < n; i++) {
if (eq[i][104] == 1) { // Hala 1 olan kart var mı?
// Bu kartı etkileyen büyü var mı kontrol et
bool has_effect = false;
for (int j = 0; j < m; j++) {
if (eq[i][j]) {
has_effect = true;
break;
}
}
if (!has_effect) {
possible = false;
break;
}
}
}
if (!possible) {
cout << "0\n";
} else {
cout << used.size() << "\n";
for (int x : used) {
cout << x << " ";
}
cout << "\n";
}
return 0;
}
| # | 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... |