제출 #617875

#제출 시각아이디문제언어결과실행 시간메모리
617875sokratisi열쇠 (IOI21_keys)C++17
20 / 100
3066 ms17092 KiB
#include <vector> #include <unordered_set> using namespace std; int solve(vector<int> r, vector<int> u, vector<int> v, vector<int> c, int s) { unordered_set<int> vis; unordered_set<int> keys; vis.insert(s); keys.insert(r[s]); int added = 1; int m = u.size(); while (added) { added = 0; for (int i = 0; i < m; i++) { if (vis.find(u[i]) != vis.end()) { if (vis.find(v[i]) == vis.end()) { if (keys.find(c[i]) != keys.end()) { added++; vis.insert(v[i]); keys.insert(r[v[i]]); } } } } for (int i = 0; i < m; i++) { if (vis.find(v[i]) != vis.end()) { if (vis.find(u[i]) == vis.end()) { if (keys.find(c[i]) != keys.end()) { added++; vis.insert(u[i]); keys.insert(r[u[i]]); } } } } } return vis.size(); } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { int n = r.size(); vector<int> canreach(n); for (int i = 0; i < n; i++) { canreach[i] = solve(r, u, v, c, i); // printf("%d\n", canreach[i]); } int least = canreach[0]; for (int i = 1; i < n; i++) least = min(least, canreach[i]); vector<int> ans(n, 0); for (int i = 0; i < n; i++) if (canreach[i] == least) ans[i] = 1; 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...