Submission #932613

#TimeUsernameProblemLanguageResultExecution timeMemory
932613Programmer123Keys (IOI21_keys)C++17
37 / 100
3054 ms30428 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(), 0); 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]); } std::set<int> num[N]; bool eliminated[N]; for (int i = 0; i < N; ++i) { eliminated[i] = false; } int actual[N]; for (int i = 0; i < N; ++i) { actual[i] = i; } 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); int TMP_THING = 0; 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]) { if (a < i) { TMP_THING = a; goto elim; } seen[a] = true; bfs.push(a); } } } for (auto [x, t]: edges[n]) { if (seen[x]) continue; if (found.count(t)) { if (x < i) { TMP_THING = x; goto elim; } seen[x] = true; bfs.push(x); } else { next[t].push_back(x); } } } for (int j = 0; j < N; ++j) { if (seen[j]) num[i].insert(j); } continue; elim: if (eliminated[TMP_THING]) { eliminated[i] = true; } else { TMP_THING = actual[TMP_THING]; if (num[TMP_THING].count(i)) { actual[i] = TMP_THING; } else { eliminated[i] = true; } } } size_t min = INT_MAX; for (int i = 0; i < N; ++i) { if (eliminated[i]) continue; if (actual[i] != i) continue; min = std::min(min, num[i].size()); } for (int i = 0; i < N; ++i) { if (eliminated[i]) continue; ans[i] = num[actual[i]].size() == 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...