#include<bits/stdc++.h>
using namespace std ;
const int N_M = 1e6+2 ;
int N;
int dsu[N_M][10] ;
set <int> nodes ;
int degree[N_M] ;
int cnt4 = 0, cnt3 = 0 ;
int ans4 = 1, ans3 = 4, ans1 = 0 ;
vector <int> G[N_M] ;
int var[10] ;
int indi[N_M] ;
int sz[N_M][10];
int tme = 0 ;
void Init(int N_) {
N = N_;
for ( int i = 0 ; i <= N ; ++i ) {
for ( int j = 0 ; j < 8 ; ++j ) dsu [i][j] = i, var[j] = 1, sz[i][j] = 1 ;
}
ans1 = N ;
}
int fnd ( int x, int d ) {
if ( x == dsu[x][d] ) return x ;
return dsu[x][d] = fnd ( dsu[x][d], d ) ;
}
int uni ( int x, int y, int d ) {
// cout << "join " << x << " " << y << " " << d << endl ;
int fx = fnd(x, d) , fy = fnd(y, d) ;
if ( fx == fy ) return 0 ;
sz[fy][d] += sz[fx][d] ;
dsu[fx][d] = fy ;
return 1 ;
}
int yet = 1, nodeE ;
void Link(int A, int B) {
degree[A]++ ;
degree[B]++ ;
if ( degree[A] > 3 ) cnt4++, nodeE = A ;
if ( degree[B] > 3 ) cnt4++, nodeE = B ;
ans4 &= (cnt4 < 2) ;
G[A].push_back ( B ) ;
G[B].push_back ( A ) ;
tme += 1-uni(A,B,7) ;
if ( tme == 1 && ans1 == N ) ans1 = sz[fnd(A,7)][7] ;
if ( tme > 1 ) ans1 = 0 ;
if ( cnt4 ) {
if ( yet ) {
for ( int i = 0 ; i <= N ; ++i ) {
if ( i == nodeE ) continue ;
for ( auto v:G[i] ) if ( v > i && v != nodeE) ans4 &= uni(i, v, 0) ;
}
yet = 0 ;
ans4 &= (nodes.count(nodeE)) ;
nodes.clear() ; nodes.insert (nodeE) ;
}
if ( A!=nodeE && B!=nodeE ) ans4 &= uni(A,B,0) ;
}
if ( degree[B] == 3 ) swap(A,B) ;
if ( degree[A] == 3 ) {
if ( cnt3 == 0 ) {
for ( auto v:G[A] ) nodes.insert (v) ;
nodes.insert(A) ;
int id = 1 ;
for ( auto j:nodes ) {
for ( int i = 0 ; i <= N ; ++i ) {
if ( i == j ) continue ;
for ( auto v:G[i] ) if ( v > i && v != j && (min(v, i) != min(A,B)||max(v, i) != max(A,B))) var[id] &= uni(i, v, id) ;
}
indi[j] = id ;
id++ ;
}
ans3 = nodes.size() ;
}
else {
set <int> cur ;
for ( auto v:G[A] ) if ( nodes.count(v) ) cur.insert (v) ;
if ( nodes.count(A) ) cur.insert (A) ;
nodes = cur ;
ans3 = nodes.size() ;
}
cnt3++ ;
}
if ( degree[B] == 3 ) {
set <int> cur ;
for ( auto v:G[B] ) if ( nodes.count(v) ) cur.insert (v) ;
if ( nodes.count(B) ) cur.insert (B) ;
nodes = cur ;
ans3 = nodes.size() ;
cnt3++ ;
}
// cout << A << " " << B << " " << ans3 << " " << ans4 << endl ;
if ( cnt3 ) {
set <int> cur ;
for ( auto v:nodes ) {
// cout << v << " " << var[indi[v]] << endl ;
if ( v!=A && v!=B ) var[indi[v]] &= uni(A,B,indi[v]) ;
if ( var[indi[v]] ) cur.insert ( v ) ;
}
nodes = cur ;
ans3 = nodes.size() ;
}
if ( cnt4 ) ans4 &= (nodes.size()>0) ;
}
int CountCritical() {
if ( cnt4 ) return ans4 ;
if ( cnt3 ) return ans3 ;
return ans1;
}
/*
int main() {
Init (5) ;
cout << CountCritical() << endl;
Link(0,1) ;
Link(1,2) ;
Link(2,0) ;
Link(0, 3);
Link(3,4);
Link(4, 0) ;
cout << CountCritical() << endl ;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
24320 KB |
Output is correct |
3 |
Incorrect |
18 ms |
24448 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
547 ms |
84088 KB |
Output is correct |
2 |
Incorrect |
1506 ms |
116092 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
24320 KB |
Output is correct |
3 |
Incorrect |
18 ms |
24448 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
24320 KB |
Output is correct |
3 |
Incorrect |
18 ms |
24448 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
24320 KB |
Output is correct |
3 |
Incorrect |
18 ms |
24448 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |