Cod sursa(job #1141781)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 13 martie 2014 10:03:04
Problema Aprindere Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

const int Nmax = 1002;

vector <int> G[Nmax];
int state[Nmax], TIME[Nmax];
int timp;

int N, M;

int main()
{
    ifstream f("aprindere.in");
    ofstream g("aprindere.out");

    f >> N >> M;

    for ( int i = 1; i <= N; ++i )
            f >> state[i];

    for ( int i = 1, ind, nrc, val; i <= M; ++i )
    {
        f >> ind;
        ind++;

        f >> TIME[ ind ];
        f >> nrc;

        for ( int j = 1; j <= nrc; ++j )
        {
            f >> val;
            val++;
            G[ind].push_back( val );
        }
    }

    for ( int i = 1; i <= N; ++i )
    {
        if ( state[i] == 0 )
        {
            timp += time[i];

            for ( auto x: G[i] )
                    state[ x ] ^= 1;
        }
    }

    g << timp << "\n";

    return 0;
}