Cod sursa(job #2716414)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 5 martie 2021 10:09:58
Problema Aprindere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 1024;
int N, M, C, T[NMAX], NRC, ans;
vector<int> adj[NMAX];
bool a[NMAX];

int main() {
    fin >> N >> M;
    for(int i = 0; i < N; ++i)
        fin >> a[i];
    for(int i = 0; i < M; ++i) {
        fin >> C;
        fin >> T[C] >> NRC;
        adj[C].resize(NRC);
        for(int &x : adj[C])
            fin >> x;
    }
    for(int i = 0; i < N; ++i)
        if(!a[i]) {
            ans += T[i];
            for(const int &x : adj[i])
                a[x] ^= 1;
            if(!a[i]) {
                fout << "-1\n";
                return 0;
            }
        }
    fout << ans << '\n';
}