Cod sursa(job #2558374)

Utilizator nonamemb10ksimion nonamemb10k Data 26 februarie 2020 15:42:47
Problema Aprindere Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.41 kb
#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;
}