Submission #145126

# Submission time Handle Problem Language Result Execution time Memory
145126 2019-08-18T21:10:59 Z bogdan_buzatu Alkemija (COCI18_alkemija) C++14
16 / 80
212 ms 12836 KB
#include <iostream>
#include <vector>
using namespace std;

struct reactie{
    int needed;
    int contsol;
    int contramase;
    vector<int>soli;
}v[100010];

vector<int>a[100010];
int freq[100010],checked[100010],q[100010];
int rightd,lefts=1;
int n,m,x;
int k,y,curent,curentt,cont;


int main(){
    cin>>n>>m;

    for(int i=1;i<=m;i++){
        cin>>x;
        freq[x]=1;
    }
    cin>>k;

    for(int i=1;i<=k;i++){
        cin>>v[i].contsol>>v[i].needed;
        v[i].contramase=v[i].contsol;
        for(int j=1;j<=v[i].contsol;j++){
            cin>>x;
            a[x].push_back(i);
            if(freq[x]==1){
                v[i].contramase--;
                if(v[i].contramase==0){
                    rightd++;
                    q[lefts]=i;
                    checked[i]=1;
                }
            }
        }
        for(int j=1; j<=v[i].needed; j++){
            cin>>x;
            v[i].soli.push_back(x);
        }
    }

    while(lefts<=rightd){
        curent=q[lefts];
        for(int i=0; i<v[curent].soli.size(); i++){
            y=v[curent].soli[i];
            if(freq[y]==0){
                freq[y]=1;
                for(int j=0; j<a[y].size(); j++){
                    curentt=a[y][j];
                    if(checked[curentt]==0){
                        v[curentt].contramase--;
                        if(v[curentt].contramase==0){
                            rightd++;
                            q[rightd]=curentt;
                            checked[curentt]=1;
                        }
                    }
                }
            }
        }
        lefts++;
    }

    for(int i=1;i<=n;i++){
        if (freq[i]==1){
            cont++;
        }
    }

    cout<<cont<<"\n";

    for(int i=1;i<=n;i++){
        if (freq[i]==1){
            cout<<i<<" ";
        }
    }
}

Compilation message

alkemija.cpp: In function 'int main()':
alkemija.cpp:51:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0; i<v[curent].soli.size(); i++){
                      ~^~~~~~~~~~~~~~~~~~~~~~
alkemija.cpp:55:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int j=0; j<a[y].size(); j++){
                              ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 6648 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 6648 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 6648 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 6648 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 8188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 135 ms 10528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 177 ms 12204 KB Output is correct
2 Incorrect 162 ms 11028 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 212 ms 12836 KB Output isn't correct
2 Halted 0 ms 0 KB -