Cod sursa(job #2856505)

Utilizator aparatecutupeuAmbrozie Pirgular aparatecutupeu Data 23 februarie 2022 22:35:26
Problema Balanta Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.67 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("balanta.in");
ofstream fout("balanta.out");

struct Cantarire
{
    int k;
    int st[513], dr[513];
    int r;
};

Cantarire v[1025];
int n, m;
int rasp;

void Rezolvare(int tip)
{
    bool suspecti[1025] = {};
    for (int i = 1; i <= n; i++)
        suspecti[i] = 1;

    for (int i = 1; i <= m; i++)
    {
        if ((v[i].r == 1 && tip == 1) || (v[i].r == 2 && tip == -1))
        {
            for (int j = 1; j <= v[i].k; j++)
                suspecti[v[i].dr[j]] = 0;
        }
        else if ((v[i].r == 2 && tip == 1) || (v[i].r == 1 && tip == -1))
        {
            for (int j = 1; j <= v[i].k; j++)
                suspecti[v[i].st[j]] = 0;
        }
        else if (v[i].r == 0)
        {
            for (int j = 1; j <= v[i].k; j++)
            {
                suspecti[v[i].st[j]] = 0;
                suspecti[v[i].dr[j]] = 0;
            }
        }
    }

    int nrSuspecti = 0;
    int primulSuspect = 0;
    for (int i = 1; i <= n; i++)
        if (suspecti[i])
        {
            nrSuspecti++;
            primulSuspect = i;
        }

    if (nrSuspecti == 1)
        rasp = primulSuspect;
}

int main()
{
    fin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        fin >> v[i].k;
        for (int j = 1; j <= v[i].k; j++)
            fin >> v[i].st[j];
        for (int j = 1; j <= v[i].k; j++)
            fin >> v[i].dr[j];
        fin >> v[i].r;
    }

    Rezolvare(1);
    if (rasp != 0)
    {
        fout << rasp;
    }
    else
    {
        Rezolvare(-1);
        fout << rasp;
    }

    return 0;
}