# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443406 | urd05 | Keys (IOI21_keys) | C++17 | 946 ms | 24248 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 <bits/stdc++.h>
using namespace std;
int ret[2000];
int p[2000];
set<int> s[2000];
bool used[2000];
typedef pair<int,int> P;
vector<P> edge[2000];
int find(int a) {
return p[a]<0?a:p[a]=find(p[a]);
}
void merge(int a,int b) {
a=find(a);
b=find(b);
if (a==b) {
return;
}
if (s[a].size()<s[b].size()) {
swap(a,b);
}
for(auto now:s[b]) {
if (!used[now])
s[a].insert(now);
}
p[a]+=p[b];
p[b]=a;
s[b].clear();
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
int n=r.size();
int m=c.size();
for(int i=0;i<m;i++) {
edge[c[i]].push_back(P(u[i],v[i]));
}
int mn=1e9;
vector<int> vec(n);
for(int i=0;i<n;i++) {
memset(p,-1,sizeof(p));
for(int j=0;j<n;j++) {
used[j]=false;
s[j].clear();
s[j].insert(r[j]);
}
while (1) {
int key=-1;
vector<int> temp;
for(auto now:s[find(i)]) {
if (used[now]) {
temp.push_back(now);
continue;
}
else {
key=now;
break;
}
}
for(int j=0;j<temp.size();j++) {
s[find(i)].erase(temp[j]);
}
//printf("%d\n",key);
if (key==-1) {
break;
}
used[key]=true;
for(int j=0;j<edge[key].size();j++) {
merge(edge[key][j].first,edge[key][j].second);
}
}
ret[i]=-p[find(i)];
mn=min(mn,ret[i]);
}
for(int i=0;i<n;i++) {
if (ret[i]==mn) {
vec[i]=1;
}
else {
vec[i]=0;
}
}
return vec;
}
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... |