#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define itr ::iterator
typedef pair<int,int> pii;
const int MAX=1e6;
vector<int> vec[MAX];
int linear[4],destruct[4],deg[4][MAX],OtherEnd[4][MAX];
int N,CycleSize,Quad;
void Init(int N_)
{
N=N_;
Quad=0;
CycleSize=0;
for(int A=0;A<N;A++)
{
deg[0][A]=0;
OtherEnd[0][A]=A;
vec[A].clear();
}
return ;
}
void Add(int X,int Y)
{
int a,b;
for(int A=0;A<4;A++)
{
if(!linear[A])
continue;
if(destruct[A]==X or destruct[A]==Y)
continue;
deg[A][X]++;
deg[A][Y]++;
if(deg[A][X]>=3 or deg[A][Y]>=3 or OtherEnd[A][X]==Y)
{
linear[A]=0;
continue;
}
a=OtherEnd[A][X];
b=OtherEnd[A][Y];
OtherEnd[A][X]=-1;
OtherEnd[A][Y]=-1;
OtherEnd[A][a]=b;
OtherEnd[A][b]=a;
}
return ;
}
void Split(int X)
{
destruct[0]=X;
destruct[1]=vec[X][0];
destruct[2]=vec[X][1];
destruct[3]=vec[X][2];
for(int A=0;A<4;A++)
{
linear[A]=1;
for(int B=0;B<N;B++)
{
deg[A][B]=0;
OtherEnd[A][B]=B;
}
}
for(int A=0;A<N;A++)
for(auto B:vec[A])
if(A<B)
Add(A,B);
return ;
}
void Link(int A,int B)
{
int X=A,Y=B,a,b;
vec[X].pb(Y);
vec[Y].pb(X);
if(Quad==0)
{
deg[0][X]++;
deg[0][Y]++;
if(deg[0][X]==3)
{
Quad=1;
Split(X);
return ;
}
if(deg[0][Y]==3)
{
Quad=1;
Split(Y);
return ;
}
if(OtherEnd[0][X]!=Y)
{
a=OtherEnd[0][X];
b=OtherEnd[0][Y];
OtherEnd[0][X]=-1;
OtherEnd[0][Y]=-1;
OtherEnd[0][a]=b;
OtherEnd[0][b]=a;
}
else
{
int cur=X,pre=X;
do
{
CycleSize++;
if(vec[cur][0]==pre)
{
pre=cur;
cur=vec[cur][1];
}
else
{
pre=cur;
cur=vec[cur][0];
}
}
while(cur!=X);
}
}
else
Add(X,Y);
return ;
}
int CountCritical()
{
if(!Quad)
{
if(CycleSize)
return CycleSize;
else
return N;
}
else
return (linear[0]+linear[1]+linear[2]+linear[3]);
}
/*signed main()
{
ios_base::sync_with_stdio(false);
Init(7);
cout<<CountCritical()<<"\n";
Link(1,2);
cout<<CountCritical()<<"\n";
Link(0,5);
cout<<CountCritical()<<"\n";
Link(2,0);
cout<<CountCritical()<<"\n";
Link(3,2);
cout<<CountCritical()<<"\n";
Link(3,5);
cout<<CountCritical()<<"\n";
Link(4,3);
cout<<CountCritical()<<"\n";
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
24316 KB |
Output is correct |
3 |
Correct |
24 ms |
24384 KB |
Output is correct |
4 |
Correct |
22 ms |
24384 KB |
Output is correct |
5 |
Correct |
31 ms |
24384 KB |
Output is correct |
6 |
Correct |
25 ms |
24384 KB |
Output is correct |
7 |
Correct |
23 ms |
24384 KB |
Output is correct |
8 |
Incorrect |
26 ms |
24384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
474 ms |
44336 KB |
Output is correct |
2 |
Correct |
1265 ms |
74296 KB |
Output is correct |
3 |
Correct |
999 ms |
82620 KB |
Output is correct |
4 |
Correct |
1343 ms |
82620 KB |
Output is correct |
5 |
Correct |
1368 ms |
82620 KB |
Output is correct |
6 |
Correct |
1381 ms |
82620 KB |
Output is correct |
7 |
Correct |
909 ms |
82620 KB |
Output is correct |
8 |
Correct |
1865 ms |
82908 KB |
Output is correct |
9 |
Correct |
2197 ms |
86652 KB |
Output is correct |
10 |
Incorrect |
1193 ms |
86652 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
24316 KB |
Output is correct |
3 |
Correct |
24 ms |
24384 KB |
Output is correct |
4 |
Correct |
22 ms |
24384 KB |
Output is correct |
5 |
Correct |
31 ms |
24384 KB |
Output is correct |
6 |
Correct |
25 ms |
24384 KB |
Output is correct |
7 |
Correct |
23 ms |
24384 KB |
Output is correct |
8 |
Incorrect |
26 ms |
24384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
24316 KB |
Output is correct |
3 |
Correct |
24 ms |
24384 KB |
Output is correct |
4 |
Correct |
22 ms |
24384 KB |
Output is correct |
5 |
Correct |
31 ms |
24384 KB |
Output is correct |
6 |
Correct |
25 ms |
24384 KB |
Output is correct |
7 |
Correct |
23 ms |
24384 KB |
Output is correct |
8 |
Incorrect |
26 ms |
24384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
24316 KB |
Output is correct |
3 |
Correct |
24 ms |
24384 KB |
Output is correct |
4 |
Correct |
22 ms |
24384 KB |
Output is correct |
5 |
Correct |
31 ms |
24384 KB |
Output is correct |
6 |
Correct |
25 ms |
24384 KB |
Output is correct |
7 |
Correct |
23 ms |
24384 KB |
Output is correct |
8 |
Incorrect |
26 ms |
24384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |