Advertisement
CyberN00b

Untitled

Dec 4th, 2022
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define LINT long long int
  3.  
  4. using namespace std;
  5.  
  6. void print(vector<pair<int, int>> v){
  7.     for(const auto& x : v)
  8.         cout << x.first << ' ' << x.second << endl;
  9. }
  10.  
  11. bool check(int index, vector<unordered_map<int, int> >& vc, vector<pair<int, int>>& z, vector<int>& test) {
  12.     for (auto it = vc[index].begin(); it != vc[index].end(); ++it) {
  13.         switch (test[it->first])
  14.         {
  15.             case 1:
  16.                 test[index] = 1;
  17.                 vc[index] = {0, 0};
  18.                 return false;
  19.             case 2:
  20.                 z[index].first += z[it->first].first * it->second;
  21.                 z[index].first += z[it->first].second * it->second;
  22.                 break;
  23.             case 0:
  24.                 check(it->first, vc, z, test);
  25.                 break;
  26.         }
  27.     }
  28. }
  29.  
  30. int main(){
  31.     int ZeliyaCount;
  32.     cin >> ZeliyaCount;
  33.     vector<unordered_map<int, int> > vc(ZeliyaCount);
  34.     vector<pair<int, int>> Zeliya(ZeliyaCount, {0, 0});
  35.  
  36.     Zeliya[0] = {1, 0};
  37.     Zeliya[1] = {0, 1};
  38.     for(int i = 2; i < Zeliya.size(); ++i) {
  39.         int a;
  40.         cin >> a;
  41.         for (int j = 0; j < a; ++i) {
  42.             int b;
  43.             cin >> b;
  44.             switch (b) {
  45.                 case 1:
  46.                     Zeliya[i].first++;
  47.                     break;
  48.                 case 2:
  49.                     Zeliya[i].second++;
  50.                     break;
  51.                 default:
  52.                     if (vc[i].find(b - 1) != vc[i].end())
  53.                         vc[i][b - 1]++;
  54.                     else
  55.                         vc[i].insert({b - 1, 1});
  56.             }
  57.         }
  58.     }
  59.  
  60.     vector<int> test(ZeliyaCount, 0); // 0 - !checked, 1 - checking, 2 - checked
  61.     test[0] = 2;
  62.     test[1] = 2;
  63.     for (int i = 2; i < vc.size(); ++i) {
  64.         if (!test[i])
  65.             check(i, vc, Zeliya, test);
  66.     }
  67.  
  68.     print(Zeliya);
  69.     int ansCount;
  70.     cin >> ansCount;
  71.     for(int i = 0; i < ansCount; ++i) {
  72.         int  Acount, Bcount, Zelie;
  73.         cin >> Acount >> Bcount >> Zelie;
  74.         pair<int, int> zel = Zeliya[Zelie - 1];
  75.         if(!(zel.first == 0 && zel.second == 0) &&  (zel.first <= Acount && zel.second <= Bcount))
  76.             cout << 1;
  77.         else cout << 0;
  78.     }
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement