# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63419 | Vahan | Parachute rings (IOI12_rings) | C++17 | 4043 ms | 86712 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<vector>
#include<iostream>
using namespace std;
vector<int> g[2000000];
int n,u[2000000],q,p;
int sz[2000000],pa[2000000];
int CountCritical();
void crset(int a)
{
sz[a]=1;
pa[a]=a;
}
int getparent(int a)
{
if(pa[a]==a)
return a;
pa[a]=getparent(pa[a]);
return pa[a];
}
void setunion(int a,int b)
{
a=getparent(a);
b=getparent(b);
if(a==b)
{
q++;
p+=sz[a];
}
if(a>b)
{
sz[a]+=sz[b];
pa[b]=a;
}
if(a<b)
{
sz[b]+=sz[a];
pa[a]=b;
}
}
void dfs(int v)
{
u[v]=1;
for(int j=0;j<g[v].size();j++)
{
int to=g[v][j];
if(u[to]==0)
dfs(to);
}
}
int stug (int x)
{
int mq=0;
for(int i=0;i<n;i++)
{
if(i==x)
continue;
int qq=0;
for(int j=0;j<g[i].size();j++)
{
int to= g[i][j];
if(to==x)
continue;
qq++;
}
if(qq==3)
return 0;
if(qq==0)
mq+=2;
if(qq==1)
mq+=1;
}
for(int i=0;i<n;i++)
u[i]=0;
u[x]=1;
int xq=0;
for(int i=0;i<n;i++)
{
if(u[i]==0)
{
dfs(i);
xq++;
}
}
if(2*xq==mq)
return 1;
else
return 0;
}
void Init(int N_) {
n = N_;
}
void Link(int A, int B) {
g[A].push_back(B);
g[B].push_back(A);
}
int CountCritical() {
for(int i=0;i<n;i++)
{
if(g[i].size()>=4)
{
if(stug(i))
return 1;
else
return 0;
}
}
for(int i=0;i<n;i++)
{
if(g[i].size()==3)
{
p=0;
if(stug(i))
p++;
for(int j=0;j<g[i].size();j++)
{
int to=g[i][j];
if(stug(to))
p++;
}
return p;
}
}
p=0;
q=0;
for(int i=0;i<n;i++)
crset(i);
for(int i=0;i<n;i++)
{
for(int j=0;j<g[i].size();j++)
{
int to=g[i][j];
if(to>i)
setunion(i,to);
}
}
if(q==1)
return p;
if(q>1)
return 0;
if(q==0)
return n;
}
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... |