Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int inv[1100005];
- int t,pom,y;
- int a,b;
- int licznik=0;
- bool visited[1100005];
- vector <int> out;
- vector <int> sas[1100005];
- int licz[1100005];
- int new_point=1000001;
- int wyn=0;
- int n,k,r;
- queue <int> q;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin>>n>>k>>r;
- for(int i=0;i<k;i++){
- cin>>inv[i];
- q.push(inv[i]);
- visited[inv[i]]=true;
- }
- for(int i=0;i<r;i++){
- new_point++;
- cin>>pom;
- for(int j=0;j<pom;j++){
- cin>>a;
- sas[a].push_back(new_point);
- licz[new_point]++;
- }
- cin>>y;
- for(int j=0;j<y;j++){
- cin>>b;
- sas[new_point].push_back(b);
- licz[b]++;
- }
- }
- while(!q.empty()){
- int top = q.front();
- q.pop();
- for(int i=0;i<sas[top].size();i++){
- licz[sas[top][i]]--;
- if(sas[top][i]>1000001&&licz[sas[top][i]]==0&&visited[sas[top][i]]==false){
- q.push(sas[top][i]);
- visited[sas[top][i]]=true;
- }
- else if(sas[top][i]<1000001&&visited[sas[top][i]]==false){
- q.push(sas[top][i]);
- visited[sas[top][i]]=true;
- if(sas[top][i]<1000001){
- wyn++;
- }
- }
- }
- }
- cout<<wyn;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement