#include <iostream>
#include <vector>
using namespace std;
const int nmax=1000*1000+5;
int n;
pair<int,int> muchii[nmax];
vector<int> v[nmax];
int grad[nmax],special[nmax],valid[nmax];
int nodspecial[10],auxiliare[10];
int maimari,busit,mme,gradmx,speciale,nr,auxi;
struct dsu
{
int tt[nmax],rg[nmax];
void ini()
{
for(int i=0;i<n;i++)
tt[i]=i,rg[i]=1;
}
int finds(int x)
{
int y=x,aux=0;
while(x!=tt[x])
x=tt[x];
while(y!=x)
{
aux=tt[y];
tt[y]=x;
y=aux;
}
return x;
}
void unite(int A,int B)
{
if(A==B) return;
if(rg[A]>rg[B]) {tt[B]=A;rg[A]+=rg[B];}
else {tt[A]=B;rg[B]+=rg[A];}
}
};
struct linker
{
dsu dsu1;
int ciclu,wciclu,mxout,gr[nmax];
void uneste(int x,int y)
{
gr[x]++;gr[y]++;
if(gr[x]>mxout) mxout=gr[x];
if(gr[y]>mxout) mxout=gr[y];
if(dsu1.finds(x)==dsu1.finds(y))
ciclu+=1,wciclu=dsu1.rg[dsu1.finds(x)];
else dsu1.unite(dsu1.finds(x),dsu1.finds(y));
}
}li[7],aux[10];
void rezolva(int x)
{
if(grad[x]>=3||(valid[x])) return;
for(int i=0;i<v[x].size();i++)
if(grad[v[x][i]]==3)
{
valid[x]=1;
}
if(!valid[x]) return;
auxi++;
auxiliare[auxi]=x;
aux[auxi].dsu1.ini();
for(int i=1;i<=nr;i++)
if(muchii[i].first!=x&&muchii[i].second!=x)
aux[auxi].uneste(muchii[i].first,muchii[i].second);
}
void spec(int x)
{
if(grad[x]==4)
{
maimari++;
if(maimari>1)
{
busit=1;
return;
}
}
if(grad[x]>=gradmx&&grad[x]>=3)
{
if(grad[x]==gradmx)
{
speciale++;
}
else
{
speciale=1;
gradmx=grad[x];
}
nodspecial[speciale]=x;
li[speciale].dsu1.ini();
if(special[x]!=speciale)
{
li[speciale].mxout=0;li[speciale].ciclu=0;li[speciale].wciclu=0;
for(int i=1;i<=nr;i++)
if(muchii[i].first!=x&&muchii[i].second!=x)
li[speciale].uneste(muchii[i].first,muchii[i].second);
special[x]=speciale;
}
}
if(gradmx==3&&speciale>4)
{
busit=1;
}
if(gradmx==3&&speciale<3)
{
for(int i=0;i<v[x].size();i++)
rezolva(v[x][i]);
}
}
void Init(int N_) {
n = N_;
li[0].dsu1.ini();
}
void Link(int A, int B) {
if(busit) return;
grad[A]++;
grad[B]++;
v[A].push_back(B);
v[B].push_back(A);
spec(A);
spec(B);
muchii[++nr]={A,B};
for(int i=0;i<=speciale;i++)
if(i==0||(nodspecial[i]!=A&&nodspecial[i]!=B))
li[i].uneste(A,B);
if(gradmx==3&&speciale<=2)
for(int i=1;i<=auxi;i++)
if(auxiliare[i]!=A&&auxiliare[i]!=B)
aux[i].uneste(A,B);
}
int CountCritical() {
if(busit)
{
return 0;
}
if(gradmx<3)
{
if(li[0].ciclu>1)
{
busit=1;
return 0;
}
if(li[0].ciclu==1)
return li[0].wciclu;
return n;
}
int ret=0;
for(int i=1;i<=speciale;i++)
{
if((!li[i].ciclu)&&li[i].mxout<3)
ret++;
}
if(gradmx==3&&speciale<=2)
{
for(int i=1;i<=auxi;i++)
if((!aux[i].ciclu)&&aux[i].mxout<3&&(!special[auxiliare[i]]))
ret++;
}
if(ret==0) busit=1;
return ret;
}
Compilation message
rings.cpp: In function 'void rezolva(int)':
rings.cpp:56:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
rings.cpp: In function 'void spec(int)':
rings.cpp:108:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24436 KB |
Output is correct |
3 |
Correct |
26 ms |
24640 KB |
Output is correct |
4 |
Correct |
24 ms |
24640 KB |
Output is correct |
5 |
Correct |
24 ms |
24640 KB |
Output is correct |
6 |
Correct |
25 ms |
24640 KB |
Output is correct |
7 |
Correct |
23 ms |
25116 KB |
Output is correct |
8 |
Correct |
23 ms |
25116 KB |
Output is correct |
9 |
Correct |
26 ms |
25116 KB |
Output is correct |
10 |
Correct |
26 ms |
25172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
494 ms |
52576 KB |
Output is correct |
2 |
Correct |
1272 ms |
105580 KB |
Output is correct |
3 |
Correct |
447 ms |
147180 KB |
Output is correct |
4 |
Correct |
1334 ms |
147180 KB |
Output is correct |
5 |
Correct |
1300 ms |
147180 KB |
Output is correct |
6 |
Correct |
1278 ms |
147180 KB |
Output is correct |
7 |
Correct |
496 ms |
169964 KB |
Output is correct |
8 |
Correct |
3190 ms |
169964 KB |
Output is correct |
9 |
Correct |
2673 ms |
169964 KB |
Output is correct |
10 |
Correct |
979 ms |
169964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24436 KB |
Output is correct |
3 |
Correct |
26 ms |
24640 KB |
Output is correct |
4 |
Correct |
24 ms |
24640 KB |
Output is correct |
5 |
Correct |
24 ms |
24640 KB |
Output is correct |
6 |
Correct |
25 ms |
24640 KB |
Output is correct |
7 |
Correct |
23 ms |
25116 KB |
Output is correct |
8 |
Correct |
23 ms |
25116 KB |
Output is correct |
9 |
Correct |
26 ms |
25116 KB |
Output is correct |
10 |
Correct |
26 ms |
25172 KB |
Output is correct |
11 |
Correct |
26 ms |
169964 KB |
Output is correct |
12 |
Correct |
35 ms |
169964 KB |
Output is correct |
13 |
Correct |
30 ms |
169964 KB |
Output is correct |
14 |
Correct |
56 ms |
169964 KB |
Output is correct |
15 |
Correct |
135 ms |
169964 KB |
Output is correct |
16 |
Correct |
27 ms |
169964 KB |
Output is correct |
17 |
Correct |
26 ms |
169964 KB |
Output is correct |
18 |
Correct |
27 ms |
169964 KB |
Output is correct |
19 |
Correct |
26 ms |
169964 KB |
Output is correct |
20 |
Correct |
32 ms |
169964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24436 KB |
Output is correct |
3 |
Correct |
26 ms |
24640 KB |
Output is correct |
4 |
Correct |
24 ms |
24640 KB |
Output is correct |
5 |
Correct |
24 ms |
24640 KB |
Output is correct |
6 |
Correct |
25 ms |
24640 KB |
Output is correct |
7 |
Correct |
23 ms |
25116 KB |
Output is correct |
8 |
Correct |
23 ms |
25116 KB |
Output is correct |
9 |
Correct |
26 ms |
25116 KB |
Output is correct |
10 |
Correct |
26 ms |
25172 KB |
Output is correct |
11 |
Correct |
26 ms |
169964 KB |
Output is correct |
12 |
Correct |
35 ms |
169964 KB |
Output is correct |
13 |
Correct |
30 ms |
169964 KB |
Output is correct |
14 |
Correct |
56 ms |
169964 KB |
Output is correct |
15 |
Correct |
135 ms |
169964 KB |
Output is correct |
16 |
Correct |
27 ms |
169964 KB |
Output is correct |
17 |
Correct |
26 ms |
169964 KB |
Output is correct |
18 |
Correct |
27 ms |
169964 KB |
Output is correct |
19 |
Correct |
26 ms |
169964 KB |
Output is correct |
20 |
Correct |
32 ms |
169964 KB |
Output is correct |
21 |
Correct |
43 ms |
169964 KB |
Output is correct |
22 |
Correct |
62 ms |
169964 KB |
Output is correct |
23 |
Correct |
71 ms |
169964 KB |
Output is correct |
24 |
Correct |
2221 ms |
169964 KB |
Output is correct |
25 |
Correct |
741 ms |
169964 KB |
Output is correct |
26 |
Incorrect |
123 ms |
169964 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24436 KB |
Output is correct |
3 |
Correct |
26 ms |
24640 KB |
Output is correct |
4 |
Correct |
24 ms |
24640 KB |
Output is correct |
5 |
Correct |
24 ms |
24640 KB |
Output is correct |
6 |
Correct |
25 ms |
24640 KB |
Output is correct |
7 |
Correct |
23 ms |
25116 KB |
Output is correct |
8 |
Correct |
23 ms |
25116 KB |
Output is correct |
9 |
Correct |
26 ms |
25116 KB |
Output is correct |
10 |
Correct |
26 ms |
25172 KB |
Output is correct |
11 |
Correct |
494 ms |
52576 KB |
Output is correct |
12 |
Correct |
1272 ms |
105580 KB |
Output is correct |
13 |
Correct |
447 ms |
147180 KB |
Output is correct |
14 |
Correct |
1334 ms |
147180 KB |
Output is correct |
15 |
Correct |
1300 ms |
147180 KB |
Output is correct |
16 |
Correct |
1278 ms |
147180 KB |
Output is correct |
17 |
Correct |
496 ms |
169964 KB |
Output is correct |
18 |
Correct |
3190 ms |
169964 KB |
Output is correct |
19 |
Correct |
2673 ms |
169964 KB |
Output is correct |
20 |
Correct |
979 ms |
169964 KB |
Output is correct |
21 |
Correct |
26 ms |
169964 KB |
Output is correct |
22 |
Correct |
35 ms |
169964 KB |
Output is correct |
23 |
Correct |
30 ms |
169964 KB |
Output is correct |
24 |
Correct |
56 ms |
169964 KB |
Output is correct |
25 |
Correct |
135 ms |
169964 KB |
Output is correct |
26 |
Correct |
27 ms |
169964 KB |
Output is correct |
27 |
Correct |
26 ms |
169964 KB |
Output is correct |
28 |
Correct |
27 ms |
169964 KB |
Output is correct |
29 |
Correct |
26 ms |
169964 KB |
Output is correct |
30 |
Correct |
32 ms |
169964 KB |
Output is correct |
31 |
Correct |
43 ms |
169964 KB |
Output is correct |
32 |
Correct |
62 ms |
169964 KB |
Output is correct |
33 |
Correct |
71 ms |
169964 KB |
Output is correct |
34 |
Correct |
2221 ms |
169964 KB |
Output is correct |
35 |
Correct |
741 ms |
169964 KB |
Output is correct |
36 |
Incorrect |
123 ms |
169964 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |