Cod sursa(job #851206)

Utilizator DaNutZ2UuUUBB Bora Dan DaNutZ2UuU Data 9 ianuarie 2013 18:06:01
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 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;
}