Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int inv[1100005];
  5. int t,pom,y;
  6. int a,b;
  7. int licznik=0;
  8. bool visited[1100005];
  9. vector <int> out;
  10. vector <int> sas[1100005];
  11. int licz[1100005];
  12. int new_point=1000001;
  13. int wyn=0;
  14. int n,k,r;
  15. queue <int> q;
  16. int main()
  17. {
  18.     ios_base::sync_with_stdio(false);
  19.     cin.tie(0);
  20.     cout.tie(0);
  21.     cin>>n>>k>>r;
  22.     for(int i=0;i<k;i++){
  23.  
  24.         cin>>inv[i];
  25.         q.push(inv[i]);
  26.         visited[inv[i]]=true;
  27.     }
  28.     for(int i=0;i<r;i++){
  29.         new_point++;
  30.         cin>>pom;
  31.         for(int j=0;j<pom;j++){
  32.             cin>>a;
  33.             sas[a].push_back(new_point);
  34.             licz[new_point]++;
  35.         }
  36.         cin>>y;
  37.         for(int j=0;j<y;j++){
  38.             cin>>b;
  39.             sas[new_point].push_back(b);
  40.             licz[b]++;
  41.         }
  42.     }
  43.     while(!q.empty()){
  44.         int top = q.front();
  45.         q.pop();
  46.         for(int i=0;i<sas[top].size();i++){
  47.             licz[sas[top][i]]--;
  48.             if(sas[top][i]>1000001&&licz[sas[top][i]]==0&&visited[sas[top][i]]==false){
  49.                 q.push(sas[top][i]);
  50.                 visited[sas[top][i]]=true;
  51.             }
  52.             else if(sas[top][i]<1000001&&visited[sas[top][i]]==false){
  53.                 q.push(sas[top][i]);
  54.                 visited[sas[top][i]]=true;
  55.                 if(sas[top][i]<1000001){
  56.                     wyn++;
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     cout<<wyn;
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement