#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
const int MAX=100010;
int n,m;
int x,sz;
int k;
int R[MAX],P[MAX];
vector<int>r[MAX],p[MAX];
int bio[MAX],cnt[MAX];
deque<int>st;
vector<int>lst[MAX];
void solve(){
while(!st.empty()){
int x=st.back();
st.pop_back();
bio[x]=1;
for(int idx:lst[x]){
cnt[idx]--;
if(!cnt[idx]){
for(int j=0;j<P[idx];j++){
if(bio[p[idx][j]]) continue;
st.push_front(p[idx][j]);
}
}
}
}
}
void del(){
for(int i=1;i<=n;i++) lst[i].clear();
for(int i=1;i<=n;i++) bio[i]=0;
for(int i=0;i<MAX;i++) cnt[i]=0;
}
int main(){
cin>>n>>m;
for(int i=0;i<m;i++){
cin>>x;
st.push_back(x);
}
cin>>k;
for(int i=0;i<k;i++){
cin>>R[i]>>P[i];cnt[i]=R[i];
for(int j=0;j<R[i];j++){
cin>>x;
r[i].push_back(x);
lst[x].push_back(i);
}
for(int j=0;j<P[i];j++){
cin>>x;
p[i].push_back(x);
}
}
solve();
for(int i=1;i<=n;i++){
if(bio[i]) sz++;
}
cout<<sz<<"\n";
for(int i=1;i<=n;i++){
if(bio[i]) cout<<i<<" ";
}cout<<"\n";
del();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
7800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
7932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
7952 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
7952 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
7952 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
9536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
123 ms |
11924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
13776 KB |
Output is correct |
2 |
Incorrect |
136 ms |
13776 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
14424 KB |
Output is correct |
2 |
Correct |
184 ms |
15320 KB |
Output is correct |