Cod sursa(job #881937)

Utilizator mlupseLupse-Turpan Mircea mlupse Data 18 februarie 2013 19:29:59
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <vector>

#define MAX 1005

using namespace std;

struct room
{
    int state;
    int cost;
    vector<int> sw;
}v[MAX];

int main()
{
    int n, m, a, nr, x, cost = 0, c;
    ifstream in("aprindere.in"); in>>n>>m;
    for(int i = 0; i < n; i++) in>>v[i].state;
    for(int i = 1; i <= m; i++)
    {
        in>>a>>c>>nr;
        v[a].cost = c;
        while(nr--)
        {
            in>>x;
            v[a].sw.push_back(x);
        }
    } in.close();
    for(int i = 0; i < n; i++)
    {
        if(!v[i].state)
        {
            for(int j = 0; j < v[i].sw.size(); j++)
                v[v[i].sw[j]].state ^= 1;
            cost += v[i].cost;
        }
    }
    ofstream out("aprindere.out"); out<<cost; out.close();
    return 0;
}