# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
590539 | oleh1421 | 열쇠 (IOI21_keys) | C++17 | 17 ms | 35540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=500100;
vector<pair<int,int> >g[N];
vector<int>go[N];
vector<int>go1[N];
int ind[N];
int ind1[N];
int cnt[N];
bool used[N];
vector<int>order;
void dfs1(int v){
used[v]=true;
for (int to:go1[v]){
if (!used[to]){
dfs1(to);
}
}
order.push_back(v);
}
void dfs(int v){
used[v]=true;
for (int to:go[v]){
if (!used[to]){
dfs(to);
}
}
order.push_back(v);
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
int n=r.size();
int m=u.size();
for (int i=0;i<m;i++){
g[u[i]].push_back({c[i],v[i]});
g[v[i]].push_back({c[i],u[i]});
}
for (int i=0;i<n;i++){
sort(g[i].begin(),g[i].end());
}
vector<pair<int,int> >ans;
vector<vector<int> >comp;
for (int i=0;i<n;i++){
comp.push_back({i});
ind[i]=i;
}
int Cnt=-1;
while (!comp.empty()){
// if ((int)comp.size()>Cnt) exit(1);
Cnt++;
// cout<<"IT\n";
for (auto u:comp){
set<int>st;
for (int v:u) st.insert(r[v]);
// for (int x:st) cout<<x<<" ";
// cout<<endl;
if (st.size()<Cnt) goto A;
int cnt=0;
for (int v:u){
for (auto [c,to]:g[v]){
if (st.find(c)==st.end()) continue;
if (ind[v]==ind[to] || ind[to]==-1) continue;
go[ind[v]].push_back(ind[to]);
go1[ind[to]].push_back(ind[v]);
}
}
if (go[ind[u[0]]].empty()){
for (int v:u){
ans.push_back({u.size(),v});
}
}
}
bool ok=false;
for (int i=0;i<n;i++){
if (ind[i]==i && !used[i]){
if (go[i].empty()){
ok=true;
dfs1(i);
}
}
}
vector<int>V;
for (int i=0;i<n;i++){
if (ind[i]!=i) continue;
if (!used[i]){
V.push_back(i);
}
}
for (int i=0;i<n;i++){
if (ind[i]==-1) continue;
if (used[ind[i]]) ind[i]=-1;
}
order.clear();
for (int i:V){
if (!used[i]) dfs(i);
}
reverse(order.begin(),order.end());
V=order;
order.clear();
for (int i:V) used[i]=false;
int last=comp.size();
comp.clear();
int cn=0;
set<int>st;
for (int i:V){
// cout<<"X "<<i<<endl;
if (!used[i]){
dfs1(i);
for (int j:order) ind1[j]=i;
if (order.size()>1) ok=true;
order.clear();
cn++;
st.insert(i);
}
}
for (int i=0;i<n;i++){
go[i].clear();
go1[i].clear();
cnt[i]=0;
used[i]=false;
}
for (int i=0;i<n;i++){
if (ind[i]==-1) continue;
ind[i]=ind1[ind[i]];
go[ind[i]].push_back(i);
}
for (int i=0;i<n;i++){
if (!go[i].empty()) {
if (st.find(i)==st.end()) exit(1);
comp.push_back(go[i]);
}
go[i].clear();
}
}
A:;
sort(ans.begin(),ans.end());
while (!ans.empty() && ans[0].first<ans.back().first) ans.pop_back();
vector<int>bt(n,0);
// for (auto cur:ans) bt[cur.second]=1;
return bt;
}
컴파일 시 표준 에러 (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... |