# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
827082 | vnm06 | Simurgh (IOI17_simurgh) | C++14 | 1076 ms | 2472 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 "simurgh.h"
using namespace std;
int sg=0;
int par[500], db[500];
bool prov[500000];
int ans[500000];
vector<int> added_edges;
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v)
{
int m=u.size();
for(int i=0; i<n; i++)
{
///for(int j=0; j<sg; j++) //cout<<added_edges[j]<<" ";
//cout<<endl;
if(added_edges.size()==n-1) return added_edges;
for(int i=0; i<n; i++)
{
par[i]=i;
db[i]=1;
}
for(int j=0; j<sg; j++)
{
int v1=u[added_edges[j]], v2=v[added_edges[j]];
while(v1!=par[v1]) v1=par[v1];
while(v2!=par[v2]) v2=par[v2];
if(db[v1]>db[v2]) par[v2]=v1;
else if(db[v1]>db[v2]) par[v1]=v2;
else
{
par[v2]=v1;
db[v1]++;
}
}
///for(int i=0; i<n; i++) //cout<<par[i]<<endl;
int cmp=i;
while(cmp!=par[cmp]) cmp=par[cmp];
for(int j=0; j<m; j++)
{
int v1=u[j], v2=v[j];
while(v1!=par[v1]) v1=par[v1];
while(v2!=par[v2]) v2=par[v2];
if(v1==v2 || v1==cmp || v2==cmp) continue;
added_edges.push_back(j);
if(db[v1]>db[v2]) par[v2]=v1;
else if(db[v1]>db[v2]) par[v1]=v2;
else
{
par[v2]=v1;
db[v1]++;
}
}
int mist=1e9, mast=-1;
for(int j=0; j<m; j++) ans[j]=-1;
for(int j=0; j<m; j++)
{
if(prov[j]) continue;
int v1=u[j], v2=v[j];
while(v1!=par[v1]) v1=par[v1];
while(v2!=par[v2]) v2=par[v2];
if(v1!=cmp && v2!=cmp) continue;
if(v1==v2) continue;
added_edges.push_back(j);
ans[j]=count_common_roads(added_edges);
if(ans[j]>mast) mast=ans[j];
if(ans[j]<mist) mist=ans[j];
added_edges.resize(added_edges.size()-1);
}
added_edges.resize(sg);
for(int j=0; j<m; j++)
{
if(ans[j]==mast)
{
added_edges.push_back(j);
sg++;
}
}
}
return added_edges;
}
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... |