CSES - Datatähti 2024 loppu - Results
Submission details
Task:Peli
Sender:EeliH
Submission time:2024-01-20 15:22:36 +0200
Language:C++17
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool paasee(int, int, int)':
input/code.cpp:32:30: error: 'class std::unordered_set<int>' has no member named 'contains'
   32 |                 if (!kaydaan.contains(neighneighbor)) {
      |                              ^~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;

vector<int> teleportit[10000];
int (etaisyydet[2500])[2500];
int n, m, q;

bool paasee(int a, int b, int c)
{
    vector<int> next;
    vector<int> nextnext;
    unordered_set<int> kaydaan;

    if (a == b && c == 0) {
        return true;
    }

    for (auto neighbor : teleportit[a]) {
        next.push_back(neighbor);
    }

    while (c > 0) {
        c--;

        for (auto neighbor : next) {
            kaydaan.erase(neighbor);
            if (c == 0 && neighbor == b) {
                return true;
            }

            for (auto neighneighbor : teleportit[neighbor]) {
                if (!kaydaan.contains(neighneighbor)) {
                    nextnext.push_back(neighneighbor);
                    kaydaan.insert(neighneighbor);
                }
            }
        }

        next = nextnext;
        nextnext = {};
    }

    return false;
}

int main()
{
    cin >> n >> m >> q;

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;

        teleportit[a].push_back(b);
        teleportit[b].push_back(a);
    }

    for (int i = 0; i < q; i++) {
        int a, b, c;
        cin >> a >> b >> c;

        if (paasee(a, b, c)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}