This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |