Cod sursa(job #198675)

Utilizator alexeiIacob Radu alexei Data 13 iulie 2008 18:48:22
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include<vector>
#include<stdio.h>
#define nmax 1024
#define mult 10024
using namespace std;

short a[nmax];
vector < int > q[nmax];

int main(){
    
 freopen("aprindere.in","r",stdin);
 freopen("aprindere.out","w",stdout);
 
 int N,M;
 scanf("%d%d",&N,&M);
 
 int i;
 vector< int >::iterator it; 
 for(i=0; i<N; ++i){
 scanf("%d",&a[i]);
 } 
 int C,T,Nr,aux;

 for(i=1; i<=M; ++i){
 scanf("%d%d%d",&C,&T,&Nr);
 q[C].push_back(T);
 while( Nr-- ){
 scanf("%d",&aux);
 q[C].push_back(aux);
 }
 }
 
 int solfin=0;          
 for(i=0; i<N; ++i){
 if( !a[i] ){
 it=q[i].begin();
 T=*it;
 ++it;
   for(; it!=q[i].end(); ++it){
         if( !a[*it] )
         a[*it]=1;
         else
         a[*it]=0;
         }
   solfin+=T;
 } 
 }
 
 printf("%d\n",solfin);
    
    return 0;
}