Pagini recente » Cod sursa (job #583562) | Cod sursa (job #448844) | Cod sursa (job #2724178) | Cod sursa (job #2325443) | Cod sursa (job #2558374)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("aprindere.in");
ofstream out("aprindere.out");
int n,m,i,j,v[100],ma[100][100],aux,timp=0, aux1;
void citire()
{
in>>n>>m;
///cout<<n<<" "<<m<<endl;
for(i=1;i<=n;i++)
{
in>>v[i];
///cout<<v[i]<<" ";
}
///cout<<endl;
for(j=1;j<=m;j++)
{
in>>aux1;
aux1++;
///cout<<aux1<<" ";
in>>ma[aux1][0];
///cout<<ma[aux1][0]<<" ";
in>>aux;
///cout<<aux<<" ";
for(i=1;i<=aux;i++)
{
in>>ma[aux1][i];
ma[aux1][i]++;
///cout<<ma[aux1][i]<<" ";
}
ma[aux1][i]=-1;
///cout<<endl;
}
}
void terbuie()
{
int g;
for(g=0;g<=n;g++)
ma[g][1]=-1;
}
void apelare_bec()
{
v[i]=1;
///cout<<"timp1:"<<timp;
timp=timp+ma[i][0];
///cout<<" timp2:"<<timp<<" i:"<<i<<" valt:"<<ma[i][0];
j=1;
while(ma[i][j]!=-1)
{
if(v[ma[i][j]]==0)
v[ma[i][j]]=1;
else
v[ma[i][j]]=0;
j++;
}
}
void solve()
{
for(i=1;i<=n;i++)
{
if(v[i]==0)
{
apelare_bec();
}
}
out<<timp;
}
int main()
{
terbuie();
citire();
solve();
return 0;
}