Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define LINT long long int
- using namespace std;
- void print(vector<pair<int, int>> v){
- for(const auto& x : v)
- cout << x.first << ' ' << x.second << endl;
- }
- bool check(int index, vector<unordered_map<int, int> >& vc, vector<pair<int, int>>& z, vector<int>& test) {
- for (auto it = vc[index].begin(); it != vc[index].end(); ++it) {
- switch (test[it->first])
- {
- case 1:
- test[index] = 1;
- vc[index] = {0, 0};
- return false;
- case 2:
- z[index].first += z[it->first].first * it->second;
- z[index].first += z[it->first].second * it->second;
- break;
- case 0:
- check(it->first, vc, z, test);
- break;
- }
- }
- }
- int main(){
- int ZeliyaCount;
- cin >> ZeliyaCount;
- vector<unordered_map<int, int> > vc(ZeliyaCount);
- vector<pair<int, int>> Zeliya(ZeliyaCount, {0, 0});
- Zeliya[0] = {1, 0};
- Zeliya[1] = {0, 1};
- for(int i = 2; i < Zeliya.size(); ++i) {
- int a;
- cin >> a;
- for (int j = 0; j < a; ++i) {
- int b;
- cin >> b;
- switch (b) {
- case 1:
- Zeliya[i].first++;
- break;
- case 2:
- Zeliya[i].second++;
- break;
- default:
- if (vc[i].find(b - 1) != vc[i].end())
- vc[i][b - 1]++;
- else
- vc[i].insert({b - 1, 1});
- }
- }
- }
- vector<int> test(ZeliyaCount, 0); // 0 - !checked, 1 - checking, 2 - checked
- test[0] = 2;
- test[1] = 2;
- for (int i = 2; i < vc.size(); ++i) {
- if (!test[i])
- check(i, vc, Zeliya, test);
- }
- print(Zeliya);
- int ansCount;
- cin >> ansCount;
- for(int i = 0; i < ansCount; ++i) {
- int Acount, Bcount, Zelie;
- cin >> Acount >> Bcount >> Zelie;
- pair<int, int> zel = Zeliya[Zelie - 1];
- if(!(zel.first == 0 && zel.second == 0) && (zel.first <= Acount && zel.second <= Bcount))
- cout << 1;
- else cout << 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement