Cod sursa(job #887636)

Utilizator superman_01Avramescu Cristian superman_01 Data 23 februarie 2013 22:30:56
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include<cstdio>
#include<vector>
#include<algorithm>

#define nmax 1005

using namespace std;

int n,state[nmax];
int t[nmax],m;
vector <int> list[nmax];
int cost;
int nr,numb,y;

void read( void )
{
	freopen("aprindere.in","r",stdin);
	scanf("%d%d",&n,&m);
	
	for( int index(0); index < n; ++index)
		scanf("%d",&state[index]);
	for(int i(0); i < m; ++i)
	{
		scanf("%d%d%d",&nr,&y,&numb);
        	t[nr]=y;	
		while(numb--)
		{
			scanf("%d",&y);
             list[nr].push_back(y);
	}
	}
	fclose(stdin);
	
}

int solve( void )
{
	

	for( int i(0) ;  i < n ; ++i)
	{
		if(state[i] == 1 )
		continue;
		cost+=t[i];
		for( int j=0 ; j < list[i].size() ; ++j )
		
			state[list[i][j]]=1-state[list[i][j]];
				
		
		
	}
	
	
}
void write ( void )
{
	freopen("aprindere.out","w",stdout);
	printf("%d",cost);
	fclose(stdout);
	
}

int main()
{
	read();
	solve();
	write();
	return 0;	
}