이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int, int>> adj[300300], st[300300];
vector<int> nxt[300300];
int col[300300], dfn[300300], INV[300300], mn[300300], out[300300], cnt = 1;
bool visited[300300];
void dfs(int s, int pa = -1){
dfn[s] = cnt++;
INV[dfn[s]] = s;
visited[s] = 1;
mn[s] = dfn[s];
out[s] = dfn[s];
///stack push
for (auto &[c, v]:adj[s]) st[c].emplace_back(s, v);
///stack pop
for (auto &[u, v]:st[col[s]]) nxt[u].push_back(v);
st[col[s]].clear();
///traverse
while(!nxt[s].empty()){
int v = nxt[s].back(); nxt[s].pop_back();
if (visited[v]) {mn[s] = min(mn[s], mn[v]); continue;}
dfs(v, s);
mn[s] = min(mn[s], mn[v]);
out[s] = out[v];
///stack pop
for (auto &[u, v]:st[col[s]]) nxt[u].push_back(v);
st[col[s]].clear();
}
}
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());
int n = r.size();
///build graph
for (int i=1;i<=n;i++){
col[i] = r[i-1];
}
for (int i=0;i<(int)u.size();i++){
adj[u[i]+1].emplace_back(c[i], v[i]+1);
adj[v[i]+1].emplace_back(c[i], u[i]+1);
}
///
for (int i=1;i<=n;i++) if (!visited[i]) dfs(i);
int rans = 1e9;
for (int i=1;i<=n;i++) if (mn[i]==dfn[i]) rans = min(rans, out[i] - dfn[i] + 1);
for (int i=1;i<=n;i++) if (mn[i]==dfn[i] && out[i]-dfn[i]+1==rans){
for (int j=dfn[i];j<=out[i];j++) ans[INV[j]-1] = 1;
}
return ans;
}
# | 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... |