# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1106626 | Ahmed57 | Sphinx's Riddle (IOI24_sphinx) | C++17 | 542 ms | 1272 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>
#include "sphinx.h"
using namespace std;
int pr2[251];
int find2(int x){
if(x==pr2[x])return x;
return pr2[x] = find2(pr2[x]);
}
void mergegroup2(int a,int b){
a = find2(a);
b = find2(b);
if(a==b)return ;
pr2[a] = b;
}
int pr[251];
vector<int> adjj[251];
int find(int x){
if(x==pr[x])return x;
return pr[x] = find(pr[x]);
}
bool mergegroup(int a,int b){
a = find(a);
b = find(b);
if(a==b)return 0;
pr[a] = b;
return 1;
}
vector<int> find_colours(int n,vector<int> X,vector<int> Y){
for(int i = 0;i<X.size();i++){
adjj[X[i]].push_back(Y[i]);
adjj[Y[i]].push_back(X[i]);
}
int d = 0;
for(int i = 0;i<n;i++){
pr2[i] = i;
}
for(int i = n-1;i>=0;i--){
int ans = 0;
while(ans!=-1){
vector<int> v;
int vis[n] = {0};
for(auto j:adjj[i]){
if(j>i&&vis[find2(j)]==0&&find2(j)!=find2(i)){
v.push_back(j);
vis[find2(j)] = 1;
}
}
int sz = v.size();
int l = 0 , r = sz-1;
ans = -1;
while(l<=r){
int mid = (l+r)/2;
vector<int> e(n,n);
e[i] = -1;
for(int j = 0;j<=mid;j++){
e[v[j]] = -1;
}
int cnt = 0;
for(int j = 0;j<n;j++){
if(e[j]==-1){
pr[j] = j;cnt++;
}else {
pr[j] = j;cnt++;
}
}
for(int j = 0;j<X.size();j++){
if(e[X[j]]==-1&&e[Y[j]]==-1){
if(X[j]==i||Y[j]==i)continue;
if(find2(X[j])==find2(Y[j]))cnt-=mergegroup(X[j],Y[j]);
}else if(e[X[j]]==n&&e[Y[j]]==n){
cnt-=mergegroup(X[j],Y[j]);
}
}
if(cnt==perform_experiment(e)){
l = mid+1;
}else {
ans = mid;
r = mid-1;
}
}
if(ans!=-1){
mergegroup2(i,v[ans]);
}
}
}
vector<int> col;
for(int i = 0;i<n;i++){
col.push_back(find2(i));
}
return col;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |