Untitled

manager.cpp
mail@pastecode.io avatar
unknown
c_cpp
8 months ago
2.0 kB
5
Indexable
Never
#include <bits/stdc++.h>
#include <unordered_set>
#include <fstream>
using namespace std;
using ll = long long;

int main(int argc, char** argv) {
    ifstream tcInput("input.txt"); // Test Case
    int n, cur,ssize;
    tcInput >> n;
    cout << n << endl;
    vector<int> v;
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        tcInput >> cur;
        v.push_back(cur);
    }
    tcInput >> ssize;
    for (int i = 0; i < ssize; i++) {
        tcInput >> cur;
        s.insert(cur);
    }
    bool f = true;
    double score = 100;
    char c;
    while (f) {
        cin >> c;
        if (c == '!') {
            f = false;
            cin >> cur;
            if (cur != ssize) {
                score = 0;
                break;
            }
            for (int i = 0; i < ssize; i++) {
                cin >> cur;
                if (!s.count(cur)) {
                    score = 0;
                    break;
                }                    
                s.erase(cur);
            }
            
        }
        else if (c == '?') {
            unordered_set<int> dest;
            int start, walk, dest_size;
            cin >> start;
            if (start > n) {
                score = 0;
                break;
            }
            cin >> walk;
            cin >> dest_size;
            for (int i = 0; i < dest_size; i++) {
                cin >> cur;
                if (cur > n) {
                    score = 0;
                    break;
                }
                dest.insert(cur);
            }

            for (int i = 0; i < walk; i++) {
                start = v[start-1];
            }
            if (dest.count(start)) {
                cout << 1 << endl;
            }
            else {
                cout << 0 << endl;
            }
        }

        else {
            f = false;
            score = 0;
        }
    }


    cout << score / 100 << '\n';

    tcInput.close();
    cout.close();
    cin.close();
}