Cod sursa(job #3138309)

Utilizator profinfo114Prof Info profinfo114 Data 18 iunie 2023 20:37:51
Problema Balanta Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.77 kb
#define _GLIBCXX_FILESYSTEM
#include<bits/stdc++.h>
using namespace std;
ifstream fin("balanta.in");
ofstream fout("balanta.out");
int G[1100], U[1100], A[1100], B[1100], n, m, i, j, k, r, g, u, mon, x;
int main(){
    fin >> n >> m;
    for(i = 1; i <= n; i++){
        U[i] = 1;
        G[i] = 1;
    }
    for(i = 1; i <= m; i++){
        fin >> k;
        for(j = 1; j <= n; j++){
            A[j] = 0;
            B[j] = 0;
        }
        for(j = 1; j <= k; j++){
            fin >> x;
            A[x] = 1;
        }
        for(j = 1; j <= k; j++){
            fin>>x;
            B[x] = 1;
        }
        fin >> r;
        if(r == 0){
            for(j = 1; j <= n; j++){
                if(A[j] == 1 || B[j] == 1){
                    G[j] = 0;
                    U[j] = 0;
                }
            }
        }
        if(r == 1){
            for(j = 1; j <= n; j++){
                if(A[j] == 1)
                    U[j] = 0;
                if(B[j] == 1)
                    G[j] = 0;
                if(A[j] + B[j] == 0){
                    U[j] = 0;
                    G[j] = 0;
                }
            }
        }
        if(r == 2){
            for(j = 1; j <= n; j++){
                if(A[j] == 1)
                    G[j] = 0;
                if(B[j] == 1)
                    U[j] = 0;
                if(A[j] + B[j] == 0){
                    U[j] = 0;
                    G[j] = 0;
                }
            }
        }
    }
    for(i = 1; i <= n; i++){
        if(G[i] == 1){
            g++;
            mon = i;
        }
        if(U[i] == 1){
            u++;
            mon = i;
        }
    }
    if(g + u == 1)
        fout << mon;
    else
        fout << 0;
    return 0;
}