Submission #145711

# Submission time Handle Problem Language Result Execution time Memory
145711 2019-08-20T20:20:27 Z AlexPascu007 Alkemija (COCI18_alkemija) C++
80 / 80
220 ms 12024 KB
#include <iostream>
#include <deque>
#include <vector>
#include <bitset>
#define DIM 100010
using namespace std;
struct reactie{
    int l,r,necunoscute;
    vector<int> y;
};
reactie e[DIM];
deque<int> coada;
vector<int> lista[DIM];
bitset<DIM> f,viz;
int n,m,i,j,k,x,reac,rc,nod,sol;
int main() {
    cin>>n>>m;
    for (i=1;i<=m;i++) {
        cin>>x;
        f[x]=1;
    }
    cin>>k;
    for (i=1;i<=k;i++) {
        cin>>e[i].l>>e[i].r;
        e[i].necunoscute=e[i].l;
        for (j=1;j<=e[i].l;j++) {
            cin>>x;
            lista[x].push_back(i);
            if (f[x]==1) {
                e[i].necunoscute--;
                if (e[i].necunoscute==0) {
                    coada.push_back(i);
                    viz[i]=1;
                }
            }
        }
        for (j=1;j<=e[i].r;j++) {
            cin>>x;
            e[i].y.push_back(x);
        }
    }
    while (!coada.empty()) {
        nod=coada.front();
        coada.pop_front();
        for (i=0;i<e[nod].y.size();i++) {
            rc=e[nod].y[i];
            if (f[rc]==0) {
                f[rc]=1;
                for (j=0;j<lista[rc].size();j++) {
                    reac=lista[rc][j];
                    if (viz[reac]==0) {
                        e[reac].necunoscute--;
                        if (e[reac].necunoscute==0) {
                            coada.push_back(reac);
                            viz[reac]=1;
                        }
                    }
                }
            }
        }
    }
    for (i=1;i<=100000;i++)
        if (f[i]==1)
            sol++;
    cout<<sol<<"\n";
    for (i=1;i<=100000;i++)
        if (f[i]==1)
            cout<<i<<" ";
    return 0;
}

Compilation message

alkemija.cpp: In function 'int main()':
alkemija.cpp:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i=0;i<e[nod].y.size();i++) {
                  ~^~~~~~~~~~~~~~~~
alkemija.cpp:49:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (j=0;j<lista[rc].size();j++) {
                          ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 8184 KB Output is correct
2 Correct 77 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 10104 KB Output is correct
2 Correct 153 ms 10616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 11496 KB Output is correct
2 Correct 158 ms 10836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 220 ms 12024 KB Output is correct
2 Correct 191 ms 11512 KB Output is correct