# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
441788 | alan8585 | Keys (IOI21_keys) | C++17 | 268 ms | 51868 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#include <stack>
using namespace std;
const int MAXN = 300100;
int T, in[MAXN], low[MAXN], instack[MAXN], bs[MAXN];
vector<int> e[MAXN];
stack<int> st;
vector<vector<int>> SCC;
vector<int> flags;
void dfs(int a) {
instack[a] = 1;
st.push(a);
in[a] = low[a] = ++T;
for(int i : e[a]) {
if(!in[i]) {
dfs(i);
low[a] = min(low[a], low[i]);
} else if(instack[i]) {
low[a] = min(low[a], in[i]);
}
}
if(in[a] == low[a]) {
int now = -1;
SCC.push_back(vector<int>(0));
do {
now = st.top();
st.pop();
SCC.back().push_back(now);
bs[now] = SCC.size();
instack[now] = 0;
} while(now != a);
}
}
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(), m = u.size();
for(int i = 0; i < m; i++) {
if(r[u[i]] == c[i])
e[u[i]].push_back(v[i]);
if(r[v[i]] == c[i])
e[v[i]].push_back(u[i]);
}
for(int i = 0; i < n; i++) {
if(!in[i]) {
dfs(i);
}
}
int nmin = MAXN;
for(int i = 0; i < (int)SCC.size(); i++) {
int flag = 1;
for(int j : SCC[i]) {
for(int k : e[j]) {
if(bs[k] != i + 1)
flag = 0;
}
}
flags.push_back(flag);
if(flag) {
nmin = min(nmin, (int)SCC[i].size());
}
}
for(int i = 0; i < (int)SCC.size(); i++) {
if(flags[i] && SCC[i].size() == nmin) {
for(int j : SCC[i])
ans[j] = 1;
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |