#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
int n;
int deg[10][nmax];
int ret;
vector< int > adj[nmax];
int parent[10][nmax];
int SZ[nmax];
void Init(int N)
{
n=N;
ret=n;
for(int i=0;i<n;i++)
{
parent[0][i]=i;
SZ[i]=1;
}
}
set<int> big;
bool forced_small_group=0;
int root(int id,int node)
{
if(parent[id][node]==node)return parent[id][node];
parent[id][node]=root(id,parent[id][node]);
return parent[id][node];
}
bool cycle;
vector< pair<int,int> > edges;
set<int> nums;
int ordered[10],pointer=0;
bool valid[10];
void small_group(int A,int B)
{
//cout<<"small group "<<A<<" "<<B<<endl;
for(int i=1;i<=pointer;i++)
if(valid[i]&&A!=ordered[i]&&B!=ordered[i])
{
deg[i][A]++;
deg[i][B]++;
if(root(i,A)==root(i,B)||deg[i][A]>=3||deg[i][B]>=3)
{
valid[i]=0;
ret--;
continue;
}
parent[i][root(i,A)]=root(i,B);
}
//for(int i=1;i<=pointer;i++)cout<<ordered[i]<<" "<<valid[i]<<endl;
}
void create_small()
{
for(auto k:big)
{
nums.insert(k);
for(auto p:adj[k])
nums.insert(p);
}
ret=0;
for(auto k:nums)
{
pointer++;
ordered[pointer]=k;
valid[pointer]=1;
ret++;
for(int j=0;j<n;j++)
parent[pointer][j]=j;
//cout<<"k= "<<k<<endl;
}
for(auto k:edges)
small_group(k.first,k.second);
}
void Link(int A, int B)
{
edges.push_back({A,B});
adj[A].push_back(B);
adj[B].push_back(A);
if(ret==0)return;
if(forced_small_group)
{
small_group(A,B);
return;
}
deg[0][A]++;
deg[0][B]++;
if(deg[0][A]>=3)big.insert(A);
if(deg[0][B]>=3)big.insert(B);
if(big.size()>=1)
{
forced_small_group=1;
create_small();
return;
}
if(root(0,A)!=root(0,B))
{
SZ[root(0,B)]+=SZ[root(0,A)];
parent[0][root(0,A)]=root(0,B);
return;
}
//a cycle with no degrees >=3
if(cycle)
{
ret=0;
return;
}
//for(int i=0;i<n;i++)cout<<root(0,i)<<" "<<SZ[i]<<endl;
cycle=1;
ret=SZ[root(0,A)];
}
int CountCritical()
{
return ret;
}
/*
int main()
{
Init(7);
cout<<CountCritical()<<endl;//7
Link(1, 2);
cout<<CountCritical()<<endl;//7
Link(0, 5);
cout<<CountCritical()<<endl;//7
Link(2, 0);
cout<<CountCritical()<<endl;//7
Link(3, 2);
cout<<CountCritical()<<endl;//4
Link(3, 5);
cout<<CountCritical()<<endl;//3
Link(4, 3);
cout<<CountCritical()<<endl;//2
Init(7);
cout<<CountCritical()<<endl;//7
Link(0,1);
cout<<CountCritical()<<endl;//7
Link(1,2);
cout<<CountCritical()<<endl;//7
Link(2,0);
cout<<CountCritical()<<endl;//3
Link(3,4);
cout<<CountCritical()<<endl;//3
Link(4,5);
cout<<CountCritical()<<endl;//3
Link(5,3);
cout<<CountCritical()<<endl;//0
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23808 KB |
Output is correct |
2 |
Correct |
21 ms |
24320 KB |
Output is correct |
3 |
Correct |
16 ms |
24320 KB |
Output is correct |
4 |
Correct |
14 ms |
23936 KB |
Output is correct |
5 |
Correct |
15 ms |
24064 KB |
Output is correct |
6 |
Correct |
16 ms |
24192 KB |
Output is correct |
7 |
Correct |
14 ms |
24320 KB |
Output is correct |
8 |
Correct |
15 ms |
24064 KB |
Output is correct |
9 |
Correct |
17 ms |
24448 KB |
Output is correct |
10 |
Correct |
18 ms |
24448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
494 ms |
50268 KB |
Output is correct |
2 |
Correct |
1060 ms |
89556 KB |
Output is correct |
3 |
Correct |
930 ms |
101584 KB |
Output is correct |
4 |
Correct |
1471 ms |
74708 KB |
Output is correct |
5 |
Correct |
1538 ms |
78236 KB |
Output is correct |
6 |
Correct |
1254 ms |
77008 KB |
Output is correct |
7 |
Correct |
862 ms |
104144 KB |
Output is correct |
8 |
Correct |
1543 ms |
104400 KB |
Output is correct |
9 |
Correct |
1640 ms |
109432 KB |
Output is correct |
10 |
Correct |
878 ms |
75972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23808 KB |
Output is correct |
2 |
Correct |
21 ms |
24320 KB |
Output is correct |
3 |
Correct |
16 ms |
24320 KB |
Output is correct |
4 |
Correct |
14 ms |
23936 KB |
Output is correct |
5 |
Correct |
15 ms |
24064 KB |
Output is correct |
6 |
Correct |
16 ms |
24192 KB |
Output is correct |
7 |
Correct |
14 ms |
24320 KB |
Output is correct |
8 |
Correct |
15 ms |
24064 KB |
Output is correct |
9 |
Correct |
17 ms |
24448 KB |
Output is correct |
10 |
Correct |
18 ms |
24448 KB |
Output is correct |
11 |
Correct |
16 ms |
24448 KB |
Output is correct |
12 |
Correct |
19 ms |
24832 KB |
Output is correct |
13 |
Correct |
18 ms |
24832 KB |
Output is correct |
14 |
Correct |
26 ms |
24832 KB |
Output is correct |
15 |
Correct |
20 ms |
24832 KB |
Output is correct |
16 |
Correct |
21 ms |
24448 KB |
Output is correct |
17 |
Correct |
18 ms |
24952 KB |
Output is correct |
18 |
Correct |
19 ms |
25472 KB |
Output is correct |
19 |
Correct |
19 ms |
24576 KB |
Output is correct |
20 |
Correct |
20 ms |
24960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23808 KB |
Output is correct |
2 |
Correct |
21 ms |
24320 KB |
Output is correct |
3 |
Correct |
16 ms |
24320 KB |
Output is correct |
4 |
Correct |
14 ms |
23936 KB |
Output is correct |
5 |
Correct |
15 ms |
24064 KB |
Output is correct |
6 |
Correct |
16 ms |
24192 KB |
Output is correct |
7 |
Correct |
14 ms |
24320 KB |
Output is correct |
8 |
Correct |
15 ms |
24064 KB |
Output is correct |
9 |
Correct |
17 ms |
24448 KB |
Output is correct |
10 |
Correct |
18 ms |
24448 KB |
Output is correct |
11 |
Correct |
16 ms |
24448 KB |
Output is correct |
12 |
Correct |
19 ms |
24832 KB |
Output is correct |
13 |
Correct |
18 ms |
24832 KB |
Output is correct |
14 |
Correct |
26 ms |
24832 KB |
Output is correct |
15 |
Correct |
20 ms |
24832 KB |
Output is correct |
16 |
Correct |
21 ms |
24448 KB |
Output is correct |
17 |
Correct |
18 ms |
24952 KB |
Output is correct |
18 |
Correct |
19 ms |
25472 KB |
Output is correct |
19 |
Correct |
19 ms |
24576 KB |
Output is correct |
20 |
Correct |
20 ms |
24960 KB |
Output is correct |
21 |
Correct |
34 ms |
26104 KB |
Output is correct |
22 |
Correct |
47 ms |
27252 KB |
Output is correct |
23 |
Correct |
60 ms |
28272 KB |
Output is correct |
24 |
Correct |
70 ms |
29296 KB |
Output is correct |
25 |
Correct |
28 ms |
27640 KB |
Output is correct |
26 |
Correct |
69 ms |
31472 KB |
Output is correct |
27 |
Correct |
78 ms |
29292 KB |
Output is correct |
28 |
Correct |
71 ms |
32236 KB |
Output is correct |
29 |
Correct |
53 ms |
30580 KB |
Output is correct |
30 |
Correct |
106 ms |
30056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23808 KB |
Output is correct |
2 |
Correct |
21 ms |
24320 KB |
Output is correct |
3 |
Correct |
16 ms |
24320 KB |
Output is correct |
4 |
Correct |
14 ms |
23936 KB |
Output is correct |
5 |
Correct |
15 ms |
24064 KB |
Output is correct |
6 |
Correct |
16 ms |
24192 KB |
Output is correct |
7 |
Correct |
14 ms |
24320 KB |
Output is correct |
8 |
Correct |
15 ms |
24064 KB |
Output is correct |
9 |
Correct |
17 ms |
24448 KB |
Output is correct |
10 |
Correct |
18 ms |
24448 KB |
Output is correct |
11 |
Correct |
494 ms |
50268 KB |
Output is correct |
12 |
Correct |
1060 ms |
89556 KB |
Output is correct |
13 |
Correct |
930 ms |
101584 KB |
Output is correct |
14 |
Correct |
1471 ms |
74708 KB |
Output is correct |
15 |
Correct |
1538 ms |
78236 KB |
Output is correct |
16 |
Correct |
1254 ms |
77008 KB |
Output is correct |
17 |
Correct |
862 ms |
104144 KB |
Output is correct |
18 |
Correct |
1543 ms |
104400 KB |
Output is correct |
19 |
Correct |
1640 ms |
109432 KB |
Output is correct |
20 |
Correct |
878 ms |
75972 KB |
Output is correct |
21 |
Correct |
16 ms |
24448 KB |
Output is correct |
22 |
Correct |
19 ms |
24832 KB |
Output is correct |
23 |
Correct |
18 ms |
24832 KB |
Output is correct |
24 |
Correct |
26 ms |
24832 KB |
Output is correct |
25 |
Correct |
20 ms |
24832 KB |
Output is correct |
26 |
Correct |
21 ms |
24448 KB |
Output is correct |
27 |
Correct |
18 ms |
24952 KB |
Output is correct |
28 |
Correct |
19 ms |
25472 KB |
Output is correct |
29 |
Correct |
19 ms |
24576 KB |
Output is correct |
30 |
Correct |
20 ms |
24960 KB |
Output is correct |
31 |
Correct |
34 ms |
26104 KB |
Output is correct |
32 |
Correct |
47 ms |
27252 KB |
Output is correct |
33 |
Correct |
60 ms |
28272 KB |
Output is correct |
34 |
Correct |
70 ms |
29296 KB |
Output is correct |
35 |
Correct |
28 ms |
27640 KB |
Output is correct |
36 |
Correct |
69 ms |
31472 KB |
Output is correct |
37 |
Correct |
78 ms |
29292 KB |
Output is correct |
38 |
Correct |
71 ms |
32236 KB |
Output is correct |
39 |
Correct |
53 ms |
30580 KB |
Output is correct |
40 |
Correct |
106 ms |
30056 KB |
Output is correct |
41 |
Correct |
292 ms |
43364 KB |
Output is correct |
42 |
Correct |
663 ms |
82924 KB |
Output is correct |
43 |
Correct |
269 ms |
58352 KB |
Output is correct |
44 |
Correct |
643 ms |
102100 KB |
Output is correct |
45 |
Correct |
703 ms |
97684 KB |
Output is correct |
46 |
Correct |
922 ms |
70080 KB |
Output is correct |
47 |
Correct |
1116 ms |
70760 KB |
Output is correct |
48 |
Correct |
593 ms |
89436 KB |
Output is correct |
49 |
Correct |
806 ms |
70308 KB |
Output is correct |
50 |
Correct |
854 ms |
69844 KB |
Output is correct |
51 |
Correct |
307 ms |
66156 KB |
Output is correct |
52 |
Correct |
564 ms |
87900 KB |
Output is correct |
53 |
Correct |
463 ms |
90220 KB |
Output is correct |
54 |
Correct |
1176 ms |
94208 KB |
Output is correct |
55 |
Correct |
1054 ms |
99792 KB |
Output is correct |