#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],ab[10],abaux[10];
int maimari,busit,mme,gradmx,speciale,nr,auxi,eq3;
struct linker
{
int ciclu,wciclu,mxout;
char gr[nmax];
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(rg[A]>rg[B]) {tt[B]=A;rg[A]+=rg[B];}
else {tt[A]=B;rg[B]+=rg[A];}
}
void uneste(int x,int y)
{
gr[x]++;gr[y]++;
if(gr[x]>mxout) mxout=(int)gr[x];
if(gr[y]>mxout) mxout=(int)gr[y];
if(finds(x)==finds(y))
ciclu+=1,wciclu=rg[finds(x)];
else unite(finds(x),finds(y));
}
}li[6];
void specialul(int x)
{
speciale++;nodspecial[speciale]=x;
ab[speciale]=0;
li[speciale].mxout=0;li[speciale].ciclu=0;li[speciale].wciclu=0;
li[speciale].ini();
for(int i=0;i<n;i++)
li[speciale].gr[i]=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;
}
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]==3)
{
gradmx=3;eq3++;
if(eq3>4) busit=1;
if(!speciale)
{
specialul(x);
for(int i=0;i<v[x].size();i++)
specialul(v[x][i]);
}
return;
}
else
{
gradmx=grad[x];
if(grad[x]>3)
{
if(speciale!=special[x])
{
speciale=0;
specialul(x);
}
}
}
}
}
void Init(int N_) {
n = N_;
li[0].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=(speciale!=0);i<=speciale;i++)
if((!ab[i]))
if(i==0||(nodspecial[i]!=A&&nodspecial[i]!=B))
li[i].uneste(A,B);
for(int i=1;i<=speciale;i++)
if(li[i].mxout>=3||li[i].ciclu)
ab[i]=1;
}
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++;
else ab[i]=1;
}
if(ret==0) busit=1;
return ret;
}
Compilation message
rings.cpp: In function 'void spec(int)':
rings.cpp:83:30: 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 |
24 ms |
24436 KB |
Output is correct |
3 |
Correct |
25 ms |
24484 KB |
Output is correct |
4 |
Correct |
22 ms |
24484 KB |
Output is correct |
5 |
Correct |
24 ms |
24484 KB |
Output is correct |
6 |
Correct |
24 ms |
24484 KB |
Output is correct |
7 |
Correct |
23 ms |
24484 KB |
Output is correct |
8 |
Correct |
23 ms |
24484 KB |
Output is correct |
9 |
Correct |
32 ms |
24808 KB |
Output is correct |
10 |
Correct |
25 ms |
24808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
517 ms |
51264 KB |
Output is correct |
2 |
Correct |
1125 ms |
94040 KB |
Output is correct |
3 |
Correct |
396 ms |
94040 KB |
Output is correct |
4 |
Correct |
1291 ms |
94040 KB |
Output is correct |
5 |
Correct |
1298 ms |
94040 KB |
Output is correct |
6 |
Correct |
1257 ms |
94040 KB |
Output is correct |
7 |
Correct |
366 ms |
94040 KB |
Output is correct |
8 |
Correct |
1486 ms |
105832 KB |
Output is correct |
9 |
Correct |
1629 ms |
111196 KB |
Output is correct |
10 |
Correct |
950 ms |
111196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
24436 KB |
Output is correct |
3 |
Correct |
25 ms |
24484 KB |
Output is correct |
4 |
Correct |
22 ms |
24484 KB |
Output is correct |
5 |
Correct |
24 ms |
24484 KB |
Output is correct |
6 |
Correct |
24 ms |
24484 KB |
Output is correct |
7 |
Correct |
23 ms |
24484 KB |
Output is correct |
8 |
Correct |
23 ms |
24484 KB |
Output is correct |
9 |
Correct |
32 ms |
24808 KB |
Output is correct |
10 |
Correct |
25 ms |
24808 KB |
Output is correct |
11 |
Correct |
25 ms |
111196 KB |
Output is correct |
12 |
Correct |
28 ms |
111196 KB |
Output is correct |
13 |
Correct |
31 ms |
111196 KB |
Output is correct |
14 |
Correct |
26 ms |
111196 KB |
Output is correct |
15 |
Correct |
26 ms |
111196 KB |
Output is correct |
16 |
Correct |
26 ms |
111196 KB |
Output is correct |
17 |
Correct |
26 ms |
111196 KB |
Output is correct |
18 |
Correct |
26 ms |
111196 KB |
Output is correct |
19 |
Correct |
27 ms |
111196 KB |
Output is correct |
20 |
Correct |
30 ms |
111196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
24436 KB |
Output is correct |
3 |
Correct |
25 ms |
24484 KB |
Output is correct |
4 |
Correct |
22 ms |
24484 KB |
Output is correct |
5 |
Correct |
24 ms |
24484 KB |
Output is correct |
6 |
Correct |
24 ms |
24484 KB |
Output is correct |
7 |
Correct |
23 ms |
24484 KB |
Output is correct |
8 |
Correct |
23 ms |
24484 KB |
Output is correct |
9 |
Correct |
32 ms |
24808 KB |
Output is correct |
10 |
Correct |
25 ms |
24808 KB |
Output is correct |
11 |
Correct |
25 ms |
111196 KB |
Output is correct |
12 |
Correct |
28 ms |
111196 KB |
Output is correct |
13 |
Correct |
31 ms |
111196 KB |
Output is correct |
14 |
Correct |
26 ms |
111196 KB |
Output is correct |
15 |
Correct |
26 ms |
111196 KB |
Output is correct |
16 |
Correct |
26 ms |
111196 KB |
Output is correct |
17 |
Correct |
26 ms |
111196 KB |
Output is correct |
18 |
Correct |
26 ms |
111196 KB |
Output is correct |
19 |
Correct |
27 ms |
111196 KB |
Output is correct |
20 |
Correct |
30 ms |
111196 KB |
Output is correct |
21 |
Correct |
43 ms |
111196 KB |
Output is correct |
22 |
Correct |
59 ms |
111196 KB |
Output is correct |
23 |
Correct |
73 ms |
111196 KB |
Output is correct |
24 |
Correct |
75 ms |
111196 KB |
Output is correct |
25 |
Correct |
41 ms |
111196 KB |
Output is correct |
26 |
Correct |
75 ms |
111196 KB |
Output is correct |
27 |
Correct |
74 ms |
111196 KB |
Output is correct |
28 |
Correct |
54 ms |
111196 KB |
Output is correct |
29 |
Correct |
55 ms |
111196 KB |
Output is correct |
30 |
Correct |
93 ms |
111196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
24436 KB |
Output is correct |
3 |
Correct |
25 ms |
24484 KB |
Output is correct |
4 |
Correct |
22 ms |
24484 KB |
Output is correct |
5 |
Correct |
24 ms |
24484 KB |
Output is correct |
6 |
Correct |
24 ms |
24484 KB |
Output is correct |
7 |
Correct |
23 ms |
24484 KB |
Output is correct |
8 |
Correct |
23 ms |
24484 KB |
Output is correct |
9 |
Correct |
32 ms |
24808 KB |
Output is correct |
10 |
Correct |
25 ms |
24808 KB |
Output is correct |
11 |
Correct |
517 ms |
51264 KB |
Output is correct |
12 |
Correct |
1125 ms |
94040 KB |
Output is correct |
13 |
Correct |
396 ms |
94040 KB |
Output is correct |
14 |
Correct |
1291 ms |
94040 KB |
Output is correct |
15 |
Correct |
1298 ms |
94040 KB |
Output is correct |
16 |
Correct |
1257 ms |
94040 KB |
Output is correct |
17 |
Correct |
366 ms |
94040 KB |
Output is correct |
18 |
Correct |
1486 ms |
105832 KB |
Output is correct |
19 |
Correct |
1629 ms |
111196 KB |
Output is correct |
20 |
Correct |
950 ms |
111196 KB |
Output is correct |
21 |
Correct |
25 ms |
111196 KB |
Output is correct |
22 |
Correct |
28 ms |
111196 KB |
Output is correct |
23 |
Correct |
31 ms |
111196 KB |
Output is correct |
24 |
Correct |
26 ms |
111196 KB |
Output is correct |
25 |
Correct |
26 ms |
111196 KB |
Output is correct |
26 |
Correct |
26 ms |
111196 KB |
Output is correct |
27 |
Correct |
26 ms |
111196 KB |
Output is correct |
28 |
Correct |
26 ms |
111196 KB |
Output is correct |
29 |
Correct |
27 ms |
111196 KB |
Output is correct |
30 |
Correct |
30 ms |
111196 KB |
Output is correct |
31 |
Correct |
43 ms |
111196 KB |
Output is correct |
32 |
Correct |
59 ms |
111196 KB |
Output is correct |
33 |
Correct |
73 ms |
111196 KB |
Output is correct |
34 |
Correct |
75 ms |
111196 KB |
Output is correct |
35 |
Correct |
41 ms |
111196 KB |
Output is correct |
36 |
Correct |
75 ms |
111196 KB |
Output is correct |
37 |
Correct |
74 ms |
111196 KB |
Output is correct |
38 |
Correct |
54 ms |
111196 KB |
Output is correct |
39 |
Correct |
55 ms |
111196 KB |
Output is correct |
40 |
Correct |
93 ms |
111196 KB |
Output is correct |
41 |
Correct |
258 ms |
111196 KB |
Output is correct |
42 |
Correct |
737 ms |
111196 KB |
Output is correct |
43 |
Correct |
324 ms |
111196 KB |
Output is correct |
44 |
Correct |
352 ms |
111196 KB |
Output is correct |
45 |
Correct |
540 ms |
111196 KB |
Output is correct |
46 |
Correct |
856 ms |
111196 KB |
Output is correct |
47 |
Correct |
1086 ms |
111196 KB |
Output is correct |
48 |
Correct |
316 ms |
111196 KB |
Output is correct |
49 |
Correct |
835 ms |
111196 KB |
Output is correct |
50 |
Correct |
895 ms |
111196 KB |
Output is correct |
51 |
Correct |
357 ms |
111196 KB |
Output is correct |
52 |
Correct |
327 ms |
111196 KB |
Output is correct |
53 |
Correct |
282 ms |
111196 KB |
Output is correct |
54 |
Correct |
1304 ms |
111196 KB |
Output is correct |
55 |
Correct |
1203 ms |
111196 KB |
Output is correct |