Cod sursa(job #2958065)

Utilizator nicu_ducalNicu Ducal nicu_ducal Data 24 decembrie 2022 14:17:27
Problema Balanta Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.99 kb
#include <bits/stdc++.h>
using namespace std;

template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template <typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
using i64 = long long int;

const int INF = INT_MAX, MOD = 1e9 + 7;
const long long LINF = LLONG_MAX;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {0, 0, 0, -1, 1, -1, 1, 1, -1};
const int dy[] = {0, -1, 1, 0, 0, -1, 1, -1, 1};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

  ifstream cin("balanta.in");
  ofstream cout("balanta.out");

  int N, M; cin >> N >> M;
  vector<bool> heavy(N + 1, 0), light(N + 1, 0);
  vector<int> now(N + 1, 0);
  for (int i = 0; i < M; i++) {
    int k, r, c; cin >> k;

    now.assign(N + 1, 0);
    for (int j = 0; j < k; j++) {
      cin >> c;
      now[c] = -1;
    }
    for (int j = 0; j < k; j++) {
      cin >> c;
      now[c] = 1;
    }

    cin >> r;
    if (r == 0) {
      for (int j = 1; j <= N; j++) {
        if (now[j] == 1 or now[j] == -1)
          heavy[j] = light[j] = true;
      }
    } else if (r == 1) {
      for (int j = 1; j <= N; j++) {
        if (now[j] == -1) {
          heavy[j] = true;
        } else if (now[j] == 1) {
          light[j] = true;
        } else {
          heavy[j] = light[j] = true;
        }
      }
    } else {
      for (int j = 1; j <= N; j++) {
        if (now[j] == 1) {
          heavy[j] = true;
        } else if (now[j] == -1) {
          light[j] = true;
        } else {
          heavy[j] = light[j] = true;
        }
      }

    }
  }

  int flag = 0, ans = 0;
  for (int i = 1; i <= N; i++) {
    if (heavy[i] and light[i])
      continue;

    if (flag == 0) {
      flag = 1;
      ans = i;
    } else {
      flag = 2;
    }
  }

  if (flag == 1)
    cout << ans << "\n";
  else
    cout << "0\n";

  return 0;
}