Submission #932612

#TimeUsernameProblemLanguageResultExecution timeMemory
932612Programmer123Keys (IOI21_keys)C++17
37 / 100
3052 ms28516 KiB
#include <bits/stdc++.h>

std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
    std::vector<int> ans(r.size(), 1);
    int N = r.size();
    int M = u.size();
    std::vector<std::pair<int, int>> edges[N];//{dest, type}
    for (int i = 0; i < M; ++i) {
        edges[u[i]].emplace_back(v[i], c[i]);
        edges[v[i]].emplace_back(u[i], c[i]);
    }
    int num[N];
    for (int i = 0; i < N; ++i) {
        bool seen[N];
        for (int j = 0; j < N; ++j) {
            seen[j] = false;
        }
        seen[i] = true;
        std::set<int> found;
        std::vector<int> next[N];
        std::queue<int> bfs;
        bfs.push(i);
        while (!bfs.empty()) {
            auto n = bfs.front();
            bfs.pop();
            if (!found.count(r[n])) {
                found.insert(r[n]);
                for (auto a: next[r[n]]) {
                    if (!seen[a]) {
                        seen[a] = true;
                        bfs.push(a);
                    }
                }
            }
            for (auto [x, t]: edges[n]) {
                if (seen[x]) continue;
                if (found.count(t)) {
                    seen[x] = true;
                    bfs.push(x);
                } else {
                    next[t].push_back(x);
                }
            }
        }
        num[i] = 0;
        for (int j = 0; j < N; ++j) {
            num[i] += seen[j];
        }
    }
    int min = INT_MAX;
    for (int i = 0; i < N; ++i) {
        min = std::min(min, num[i]);
    }
    for (int i = 0; i < N; ++i) {
        ans[i] = num[i] == min;
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...