이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int cnt[600005],bio[600005],bio2[600005],n,m;
set <pair<int,int> > s;
set <int> s1[600005],s2;
vector <int> r,ans;
vector <pair<int,int> > v[600005];
void f(int p) {
for(int i=0;i<min(600000,n*3);i++) {
bio[i]=0;
bio2[i]=0;
s1[i].clear();
}
bio[p]=1;
bio2[r[p]]=1;
s.clear();
s2.clear();
s.insert(make_pair(0,p));
while(!s.empty()) {
int a=(*s.begin()).first,x=(*s.begin()).second;
if(a) break;
s.erase(s.begin());
s2.insert(x);
//cout << a << " " << x << "\n";
//system("pause");
bio[x]=1;
bio2[r[x]]=1;
for(set <int>::iterator it=s1[r[x]].begin();it!=s1[r[x]].end();it++) {
if(s.find(make_pair(1,(*it)))!=s.end()) s.erase(make_pair(1,(*it)));
s.insert(make_pair(0,(*it)));
}
s1[r[x]].clear();
for(int i=0;i<int(v[x].size());i++) {
if(bio[v[x][i].first]) continue;
//bio[v[x][i].first]=1;
s.insert(make_pair(!bio2[v[x][i].second],v[x][i].first));
if(!bio2[v[x][i].second]) s1[v[x][i].second].insert(v[x][i].first);
}
for(int i=0;i<int(v[x].size());i++) {
if(bio[v[x][i].first]) continue;
bio[v[x][i].first]=1;
}
}
//cout << "\n\n";
}
std::vector<int> find_reachable(std::vector<int> r1, std::vector<int> u1, std::vector<int> v1, std::vector<int> c1) {
n=r1.size();
m=u1.size();
r=r1;
int mini=1e9;
for(int i=0;i<m;i++) {
v[u1[i]].push_back(make_pair(v1[i],c1[i]));
v[v1[i]].push_back(make_pair(u1[i],c1[i]));
}
for(int i=0;i<n;i++) {
f(i);
cnt[i]=int(s2.size());
mini=min(mini,cnt[i]);
}
for(int i=0;i<n;i++) {
ans.push_back(cnt[i]==mini);
}
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... |