// +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+ \\
/* Some Makoto Shinkai's :
“Who cares if we can't see any sunshine? I want you more than any blue sky!!!”
- Tenki no Ko
"By the time the date is over, the comet will be visible in the sky."
- Kimi no Nawa
“No matter what happens, even if the stars fall, I will live.”
- Byōsoku 5 Centimeter
*/
#include <bits/stdc++.h>
#define Raveluk ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define g1 get<0>
#define g2 get<1>
#define g3 get<2>
#define qf q.front()
#define all(x) (x).begin(), (x).end()
using namespace std;
int main()
{
Raveluk
int n,m,i,j,k,r,x;
cin>>n>>m;
bool aseli[n+1];
int sz[n+1];
vector<int>v[n+1],adj[n+1];
memset(sz,0,sizeof(sz));
memset(aseli,false,sizeof(aseli));
queue<int>q;
for(i=1;i<=m;i++){
cin>>j;
aseli[j] = true;
}
cin>>k;
int l[k+1];
for(i=1;i<=k;i++){
cin>>l[i]>>r;
for(j=1;j<=l[i];j++){
cin>>x;
if(aseli[x]) sz[i]++;
else v[x].pb(i);
}
if(sz[i] == l[i]) q.push(i);
for(j=1;j<=r;j++){
cin>>x;
if(aseli[x]) continue;
adj[i].pb(x);
}
}
while(!q.empty()){
int node = q.front();
q.pop();
for(auto x:adj[node]){
if(aseli[x]) continue;
aseli[x] = true;
for(auto c:v[x]){
sz[c]++;
if(sz[c] == l[c]) q.push(c);
}
}
}
for(i=1;i<=n;i++){
if(aseli[i]) v[0].pb(i);
}
cout<<v[0].size()<<"\n";
for(auto x:v[0]) cout<<x<<" ";
return 0;
}
# | 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... |