# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078162 | noyancanturk | Simurgh (IOI17_simurgh) | C++17 | 125 ms | 4364 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 "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int lim=510;
int n;
int v[lim][lim];
int edgecnt[lim],p[lim];
struct{
int par[lim],sz[lim];
void init(){
for(int i=0;i<n;i++)par[i]=i,sz[i]=1;
}
int find(int i){
if(i==par[i])return i;
return par[i]=find(par[i]);
}
bool unite(int i,int j){
i=find(i),j=find(j);
if(i^j){
par[i]=j;
sz[j]+=sz[i];
return 1;
}
return 0;
}
}dsu;
void findedgecnt(int node){
vector<int>r;
for(int i=0;i<n;i++){
if(i==node)continue;
r.pb(v[node][i]);
}
edgecnt[node]=count_common_roads(r);
if(node)edgecnt[node]--;
}
int lineadd(int node){
vector<int>r;
for(int i=1;i+1<n;i++){
r.pb(v[i][i+1]);
}
r.pb(v[0][node]);
return count_common_roads(r);
}
vector<int>legit;
vector<int> find_roads(int N, vector<int> u1, vector<int> u2) {
n=N;
legit.clear();
for(int i=0;i<n;i++)p[i]=-1;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
v[i][j]=-1;
int m=u1.size();
for(int i=0;i<m;i++){
v[u1[i]][u2[i]]=i;
v[u2[i]][u1[i]]=i;
}
if(m==n*(n-1)/2){
cerr<<"here??\n";
for(int i=0;i<n;i++)findedgecnt(i);
int best=lineadd(1);
vector<int>toad;
toad.pb(1);
for(int i=2;i<n;i++){
int cnt=lineadd(i);
if(cnt==best){
toad.pb(i);
}else if(best<cnt){
best=cnt;
toad.clear();
toad.pb(i);
}
}
vector<int>q;
for(int i:toad){
q.pb(i);
p[i]=0;
legit.pb(v[0][i]);
}
while(q.size()){
int node=q.back();
q.pop_back();
vector<int>dudes;
for(int i=1;i<n;i++){
if(p[i]==-1)dudes.pb(i);
}
int tt=-1;
vector<int>found;
while(edgecnt[node]){
int l=tt+2,r=dudes.size()-1,ans=tt+1;
while(l<=r){
int mid=(l+r)>>1;
vector<int>wow=legit;
for(int i=0;i<mid;i++){
wow.pb(v[0][dudes[i]]);
}
for(int i=mid;i<dudes.size();i++){
wow.pb(v[node][dudes[i]]);
}
int cnt=count_common_roads(wow)-legit.size();
if(cnt==edgecnt[node]){
ans=mid;
l=mid+1;
}else{
r=mid-1;
}
}
found.pb(dudes[ans]);
edgecnt[node]--;
tt=ans;
}
for(int i:found){
p[i]=node;
legit.pb(v[node][i]);
q.pb(i);
}
}
return legit;
}
for(int node=0;node<n;node++){
dsu.init();
vector<int>well;
for(int i=0;i<n;i++){
if(i==node)continue;
for(int j=0;j<n;j++){
if(j==node)continue;
if(v[i][j]!=-1&&dsu.unite(i,j)){
well.pb(v[i][j]);
}
}
}
vector<int> comps[n]{};
for(int i=0;i<n;i++){
comps[dsu.find(i)].pb(i);
}
for(int cur=0;cur<n;cur++){
if(!comps[cur].size()||cur==node)continue;
vector<int>toask=well;
for(int i=0;i<n;i++){
if(i==cur||i==node||!comps[i].size())continue;
for(int j:comps[i]){
if(v[node][j]!=-1){
toask.pb(v[node][j]);
break;
}
}
}
int best=-1;
vector<int>topush;
for(int i:comps[cur]){
if(v[node][i]!=-1){
toask.pb(v[node][i]);
int cnt=count_common_roads(toask);
if(best<cnt){
topush.clear();
best=cnt;
}
if(best==cnt&&node<i){
topush.pb(v[node][i]);
}
toask.pop_back();
}
}
for(int i:topush)legit.pb(i);
}
}
return legit;
}
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... |