#include <iostream>
#include <vector>
#include <deque>
using namespace std;
int n,m,i,j,x,f[100010],k,viz[100010],react,elem,sol;
struct reactie{
int L,R,necunoscute;
vector <int> Y;} w[100010];
vector <int> lista[100010];
deque <int> coada;
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>>w[i].L>>w[i].R;
w[i].necunoscute=w[i].L;
for(j=1;j<=w[i].L;j++){
cin>>x;
lista[x].push_back(i);
if(f[x]==1){
w[i].necunoscute--;
if(w[i].necunoscute==0){
coada.push_back(i);
viz[i]=1;}
}
}
for(j=1;j<=w[i].R;j++){
cin>>x;
w[i].Y.push_back(x);
}
}
while(coada.size()){
react=coada.front();
coada.pop_front();
for(i=0;i<w[react].Y.size();i++){
elem=w[react].Y[i];
if(f[elem]==0){
f[elem]=1;
for(j=0;j<lista[elem].size();j++){
k=lista[elem][j];
if(viz[k]==0){
w[k].necunoscute--;
if(w[k].necunoscute==0){
coada.push_back(k);
viz[k]=1;
}
}
}
}
}
}
for(i=1;i<=n;i++)
if(f[i])sol++;
cout<<sol<<"\n";
for(i=1;i<=n;i++)
if(f[i])cout<<i<<" ";
return 0;
}
Compilation message
alkemija.cpp: In function 'int main()':
alkemija.cpp:39:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<w[react].Y.size();i++){
~^~~~~~~~~~~~~~~~~~
alkemija.cpp:43:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<lista[elem].size();j++){
~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6520 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 |
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 |
55 ms |
8180 KB |
Output is correct |
2 |
Correct |
85 ms |
8780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
10364 KB |
Output is correct |
2 |
Correct |
149 ms |
10876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
11860 KB |
Output is correct |
2 |
Correct |
163 ms |
11200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
209 ms |
12760 KB |
Output is correct |
2 |
Correct |
188 ms |
12104 KB |
Output is correct |