Submission #143334

# Submission time Handle Problem Language Result Execution time Memory
143334 2019-08-13T16:59:03 Z mariadinca Alkemija (COCI18_alkemija) C++14
80 / 80
210 ms 9592 KB
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

int n, m, i, j, x, reactanti, produsi, p, f[100001], crt, k, lipsa[100001], reactie;
deque<int> coada;
vector<int> reactii[100001], prod[100001];

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>>reactanti>>produsi;
        for(j=1;j<=reactanti;j++){
            cin>>x;
            reactii[x].push_back(i);
            if(f[x] == 0)
                lipsa[i]++;
        }
        if(lipsa[i] == 0)
            coada.push_back(i);
        for(j=1;j<=produsi;j++){
            cin>>x;
            prod[i].push_back(x);
        }
    }
    while(!coada.empty()){
        crt = *coada.begin();
        for(i=0;i<prod[crt].size();i++){
            p = prod[crt][i];
            if(f[p] == 0){
                for(j=0;j<reactii[p].size();j++){
                    reactie = reactii[p][j];
                    lipsa[reactie]--;
                    if(lipsa[reactie] == 0)
                        coada.push_back(reactie);
                }
                f[p] = 1;
                m++;
            }
        }
        coada.erase(coada.begin());
    }
    cout<<m<<endl;
    for(i=1;i<=n;i++)
        if(f[i] == 1)
            cout<<i<<" ";
    return 0;
}

Compilation message

alkemija.cpp: In function 'int main()':
alkemija.cpp:35:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<prod[crt].size();i++){
                 ~^~~~~~~~~~~~~~~~~
alkemija.cpp:38:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(j=0;j<reactii[p].size();j++){
                         ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 6244 KB Output is correct
2 Correct 73 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 7740 KB Output is correct
2 Correct 148 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 8892 KB Output is correct
2 Correct 161 ms 8188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 9592 KB Output is correct
2 Correct 187 ms 9152 KB Output is correct