Submission #141632

# Submission time Handle Problem Language Result Execution time Memory
141632 2019-08-08T15:01:46 Z mariusnicoli Alkemija (COCI18_alkemija) C++14
80 / 80
203 ms 12024 KB
#include <iostream>
#include <deque>
#include <vector>
#include <bitset>
using namespace std;

struct element {
    int L;
    int R;
    int necunoscute;
    vector<int> Y;
};

element e[100010];
deque<int> coada;
vector<int> Lista[100010];
int n, m, i, v, k, j, x, nod, ec, reactie, sol;
bitset<100010> f, viz;
int main () {
    cin>>n>>m;
    for (i=1;i<=m;i++) {
        cin>>v;
        f[v] = 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();
        /// nod este o lista cu toate elementele marcate
        for (i=0;i<e[nod].Y.size();i++) {
            ec = e[nod].Y[i];
            if (f[ec] == 0) {
                f[ec] = 1;
                for (j=0;j<Lista[ec].size();j++) {
                    reactie = Lista[ec][j];
                    if (viz[reactie] == 0) {
                        e[reactie].necunoscute--;
                        if (e[reactie].necunoscute == 0) {
                            coada.push_back(reactie);
                            viz[reactie] = 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:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i=0;i<e[nod].Y.size();i++) {
                  ~^~~~~~~~~~~~~~~~
alkemija.cpp:55:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (j=0;j<Lista[ec].size();j++) {
                          ~^~~~~~~~~~~~~~~~~
# 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 6648 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 10 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 8056 KB Output is correct
2 Correct 77 ms 8612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 10136 KB Output is correct
2 Correct 147 ms 10488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 11516 KB Output is correct
2 Correct 164 ms 10744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 12024 KB Output is correct
2 Correct 190 ms 11680 KB Output is correct