# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
974560 | onlk97 | Keys (IOI21_keys) | C++17 | 178 ms | 61420 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 <bits/stdc++.h>
using namespace std;
vector <int> in[300010],out[300010];
bool visited[300010];
stack <int> st;
void dfs1(int cur){
visited[cur]=1;
for (int i:out[cur]){
if (!visited[i]) dfs1(i);
}
st.push(cur);
}
vector <vector <int> > scc;
int belong[300010],idx;
vector <int> cc;
void dfs2(int cur){
cc.push_back(cur);
belong[cur]=idx;
visited[cur]=1;
for (int i:in[cur]){
if (!visited[i]) dfs2(i);
}
}
vector <int> find_reachable(vector <int> r,vector <int> u,vector <int> v,vector <int> c){
int n=r.size(),m=u.size();
for (int i=0; i<m; i++){
if (r[u[i]]==c[i]){
out[u[i]].push_back(v[i]);
in[v[i]].push_back(u[i]);
}
if (r[v[i]]==c[i]){
out[v[i]].push_back(u[i]);
in[u[i]].push_back(v[i]);
}
}
for (int i=0; i<n; i++){
if (!visited[i]) dfs1(i);
}
for (int i=0; i<n; i++) visited[i]=0;
while (!st.empty()){
int tp=st.top(); st.pop();
if (visited[tp]) continue;
dfs2(tp);
scc.push_back(cc);
idx++;
cc.clear();
}
vector <int> safe;
for (int i=0; i<n; i++){
int ok=1;
for (int j:out[i]){
if (belong[i]!=belong[j]) ok=0;
}
safe.push_back(ok);
}
int mn=1e9;
for (auto i:scc){
bool ok=1;
for (int j:i){
if (!safe[j]) ok=0;
}
if (ok) mn=min(mn,(int)i.size());
}
vector <int> ans(n,0);
for (auto i:scc){
bool ok=1;
for (int j:i){
if (!safe[j]) ok=0;
}
if (ok&&i.size()==mn){
for (int j: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... |