Cod sursa(job #1703420)

Utilizator moise_alexandruMoise Alexandru moise_alexandru Data 16 mai 2016 21:34:35
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.9 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream in("aprindere.in");
ofstream out("aprindere.out");
const int maxn = 1005;
int rez[maxn][maxn];
int v[maxn];
char T[maxn * 10];
void citire1()
{
    in.getline(T + 1, maxn * 10);
    in.getline(T + 1, maxn * 10);
    int p = strlen(T + 1);
    for(int i = 1; i <= p; i += 2)
        v[i / 2] = T[i] - '0';
}
void citire2(int m)
{
    for(int i = 1; i <= m; i++)
    {
        in.getline(T + 1, maxn);
        int p = strlen(T + 1);
        int poz = 1;
        int nr = 0;
        while(T[poz] != ' ')
        {
            nr = nr * 10 + T[poz] - '0';
            poz++;
        }
        int c = nr;
        nr = 0;
        poz++;
        while(T[poz] != ' ')
        {
            nr = nr * 10 + T[poz] - '0';
            poz++;
        }
        int t = nr;
        nr = 0;
        poz++;
        while(T[poz] != ' ')
        {
            nr = nr * 10 + T[poz] - '0';
            poz++;
        }
        int num = nr;
        nr = 0;
        poz++;
        int pozvct = 2;
        rez[c][0] = t;
        rez[c][1] = num;
        while(poz <= p)
        {
            if(T[poz] == ' ')
            {
                rez[c][pozvct] = nr;
                pozvct++;
                nr = 0;
            }
            else
                nr = nr * 10 + T[poz] - '0';
            poz++;
        }
        rez[c][pozvct] = nr;
    }
}
int main()
{
    int n, m;
    in >> n >> m;
    citire1();
    for(int i = 0; i < n; i++)
    {
        if(v[i] == 0)
            v[i]--;
    }
    citire2(m);
    int s = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i] == -1)
        {
            s = s + rez[i][0];
            for (int j = 2; j <= rez[i][1] + 1; j++)
                v[rez[i][j]] = v[rez[i][j]] * (-1);
        }
    }
    out << s;
    return 0;
}