Cod sursa(job #2433231)

Utilizator dr_personalityEftime Andrei Horatiu dr_personality Data 26 iunie 2019 14:01:24
Problema Balanta Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>

using namespace std;

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

const int rmax = 2;
const int nmax = 1024;

int n, m, k;
int r, num;
int sol, sols;

int v[1 + nmax];
int f[1 + rmax][1 + nmax];

int main() {
  cin >> n >> m;
  for(int i = 1; i <= m; i++) {
    cin >> k;
    for(int j = 1; j <= 2 * k; j++)
      cin >> v[j];
    cin >> r;
    if(r)
      num++;
    if(r == 0) {
      for(int j = 1; j <= 2 * k; j++) {
        f[1][v[j]]--;
        f[2][v[j]]--;
      }
    } else if(r == 1) {
      for(int j = 1; j <= k; j++)
        f[1][v[j]]++;
      for(int j = k + 1; j <= 2 * k; j++)
        f[2][v[j]]++;
    } else {
      for(int j = 1; j <= k; j++)
        f[2][v[j]]++;
      for(int j = k + 1; j <= 2 * k; j++)
        f[1][v[j]]++;
    }
  }
  for(int i = 1; i <= n; i++) {
    if(f[1][i] == num || f[2][i] == num) {
      sols++;
      sol = i;
    }
  }
  if(sols > 1)
    cout << 0;
  else
    cout << sol;
  return 0;
}