Cod sursa(job #3239480)

Utilizator MrPuzzleDespa Fabian Stefan MrPuzzle Data 5 august 2024 19:00:34
Problema Balanta Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.63 kb
#include <bits/stdc++.h>

#define DIM 1024

#define EMPTY 69
#define REAL 0
#define PLUS 1
#define MINUS -1

using namespace std;

//ifstream f("in.in");
//ofstream g("out.out");

ifstream f("balanta.in");
ofstream g("balanta.out");

/// EMPTY

/// MINUS (-1 -)
/// PLUS (1 +)
/// REAL (0 =)

int n,m;
int v[DIM+5];

int k;
int a[DIM+5];
int b[DIM+5];
int op;

bool filled = 0;

int cnt = 0;
int u[DIM+5];
void fillRest(){

    cnt++;

    for(int i=1;i<=k;i++){
        u[a[i]] = u[b[i]] = cnt;
    }

    for(int i=1;i<=n;i++){
        if(u[i] != cnt){
            v[i] = REAL;
        }
    }

}

void afis(){
    for(int i=1;i<=n;i++){
        cout<<i<<": ";
        if(v[i] == EMPTY){
            cout<<"EMPTY";
        }else if(v[i] == REAL){
            cout<<"REAL";
        }else if(v[i] == PLUS){
            cout<<"PLUS";
        }else if(v[i] == MINUS){
            cout<<"MINUS";
        }else{
            cout<<"??";
        }
        cout<<'\n';
    }cout<<'\n';
}

signed main()
{

    f>>n>>m;
    for(int i=1;i<=n;i++){
        v[i] = EMPTY;
    }

    for(int i=1;i<=n;i++){
        f>>k;
        for(int j=1;j<=k;j++){
            f>>a[j];
        }
        for(int j=1;j<=k;j++){
            f>>b[j];
        }
        f>>op;

        if(op == 0){
            for(int j=1;j<=k;j++){
                v[a[j]] = REAL;
                v[b[j]] = REAL;
            }
        }else if(op == 1){

            for(int j=1;j<=k;j++){
                if(v[a[j]] == EMPTY || v[a[j]] == PLUS){
                    v[a[j]] = PLUS;
                }else{
                    v[a[j]] = REAL;
                }

                if(v[b[j]] == EMPTY || v[b[j]] == MINUS){
                    v[b[j]] = MINUS;
                }else{
                    v[b[j]] = REAL;
                }
            }

            fillRest();
        }else{
            for(int j=1;j<=k;j++){
                if(v[a[j]] == EMPTY || v[a[j]] == MINUS){
                    v[a[j]] = MINUS;
                }else{
                    v[a[j]] = REAL;
                }

                if(v[b[j]] == EMPTY || v[b[j]] == PLUS){
                    v[b[j]] = PLUS;
                }else{
                    v[b[j]] = REAL;
                }
            }

            fillRest();
        }

        //afis();
    }

    int sol = 0;

    for(int i=1;i<=n;i++){
        if(v[i]!=REAL){
            if(sol == 0){
                sol = i;
            }else{
                sol = 0;
                break;
            }
        }
    }

    g<<sol;

    return 0;
}