#include <vector>
#include <iostream>
using namespace std;
int N;
vector<int> grafo[1000005];
bool C[1000005];
bool V[1000005];
int A[6];
int K;
int inizio;
bool flag;
vector<int> P[6];
bool G[1000005];
bool f2;
int res;
void DFS(int k){
for(int f:grafo[k])
if(C[f] and !V[f]){
V[f]=true;
DFS(f);
}
int x=0;
for(int f:grafo[k])
if(C[f])
x++;
x=min(x,4);
A[x]++;
if(flag){
//if(k==0)cout<<"x "<<x<<endl;
K++;
P[x].push_back(k);
}
}
void Init(int N_) {
N = N_;
}
void Link(int A, int B) {
grafo[A].push_back(B);
grafo[B].push_back(A);
}
void stampa(){
cout<<"A ";
for(int i=0;i<5;i++)
cout<<A[i]<<" ";
cout<<endl;
}
int CountCritical() {
fill(C,C+N,true);
fill(V,V+N,false);
inizio=-1;
K=0;
for(int i=0;i<5;i++)
P[i].clear();
for(int i=0;i<N;i++)
if(!V[i]){
fill(A,A+5,0);
V[i]=true;
DFS(i);
if(!(A[0]==1 or (A[1]==2 and A[3]==0 and A[4]==0))){
if(inizio==-1)
inizio=i;
else
return 0;
}
}
if(inizio==-1)
return N;
fill(C,C+N,true);
fill(V,V+N,false);
fill(A,A+5,0);
flag=true;
V[inizio]=true;
DFS(inizio);
flag=false;
for(int i=0;i<N;i++)
C[i]=V[i];
if(A[4]>1)
return 0;
else if(A[4]==1){
fill(V,V+N,false);
C[P[4][0]]=false;
f2=true;
for(int i=0;i<N;i++)
if(C[i] and !V[i]){
fill(A,A+5,0);
V[i]=true;
DFS(i);
//stampa();
if(!(A[0]==1 or (A[1]==2 and A[3]==0 and A[4]==0)))
f2=false;
}
if(f2)
return 1;
else
return 0;
}
if(A[3]==0)
return K;
else if(A[3]>4)
return 0;
fill(G,G+N,false);
for(int i:P[3]){
G[i]=true;
for(int f:grafo[i])
G[f]=true;
}
res=0;
for(int p=0;p<N;p++)
if(G[p]){
fill(V,V+N,false);
C[p]=false;
f2=true;
for(int i=0;i<N;i++)
if(C[i] and !V[i]){
fill(A,A+5,0);
V[i]=true;
DFS(i);
if(!(A[0]==1 or (A[1]==2 and A[3]==0 and A[4]==0)))
f2=false;
}
if(f2)
res++;
C[p]=true;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
24012 KB |
Output is correct |
3 |
Correct |
24 ms |
24088 KB |
Output is correct |
4 |
Correct |
22 ms |
24088 KB |
Output is correct |
5 |
Correct |
22 ms |
24136 KB |
Output is correct |
6 |
Correct |
24 ms |
24392 KB |
Output is correct |
7 |
Correct |
22 ms |
24392 KB |
Output is correct |
8 |
Correct |
23 ms |
24392 KB |
Output is correct |
9 |
Correct |
25 ms |
24392 KB |
Output is correct |
10 |
Correct |
28 ms |
24392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
549 ms |
41432 KB |
Output is correct |
2 |
Correct |
1085 ms |
51220 KB |
Output is correct |
3 |
Correct |
1205 ms |
64136 KB |
Output is correct |
4 |
Correct |
1255 ms |
64136 KB |
Output is correct |
5 |
Correct |
1255 ms |
64136 KB |
Output is correct |
6 |
Correct |
1418 ms |
81308 KB |
Output is correct |
7 |
Correct |
1053 ms |
81308 KB |
Output is correct |
8 |
Correct |
1167 ms |
81308 KB |
Output is correct |
9 |
Correct |
1294 ms |
81308 KB |
Output is correct |
10 |
Correct |
715 ms |
81308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
24012 KB |
Output is correct |
3 |
Correct |
24 ms |
24088 KB |
Output is correct |
4 |
Correct |
22 ms |
24088 KB |
Output is correct |
5 |
Correct |
22 ms |
24136 KB |
Output is correct |
6 |
Correct |
24 ms |
24392 KB |
Output is correct |
7 |
Correct |
22 ms |
24392 KB |
Output is correct |
8 |
Correct |
23 ms |
24392 KB |
Output is correct |
9 |
Correct |
25 ms |
24392 KB |
Output is correct |
10 |
Correct |
28 ms |
24392 KB |
Output is correct |
11 |
Correct |
30 ms |
81308 KB |
Output is correct |
12 |
Correct |
61 ms |
81308 KB |
Output is correct |
13 |
Correct |
62 ms |
81308 KB |
Output is correct |
14 |
Correct |
66 ms |
81308 KB |
Output is correct |
15 |
Correct |
87 ms |
81308 KB |
Output is correct |
16 |
Correct |
55 ms |
81308 KB |
Output is correct |
17 |
Correct |
30 ms |
81308 KB |
Output is correct |
18 |
Correct |
33 ms |
81308 KB |
Output is correct |
19 |
Correct |
61 ms |
81308 KB |
Output is correct |
20 |
Correct |
63 ms |
81308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
24012 KB |
Output is correct |
3 |
Correct |
24 ms |
24088 KB |
Output is correct |
4 |
Correct |
22 ms |
24088 KB |
Output is correct |
5 |
Correct |
22 ms |
24136 KB |
Output is correct |
6 |
Correct |
24 ms |
24392 KB |
Output is correct |
7 |
Correct |
22 ms |
24392 KB |
Output is correct |
8 |
Correct |
23 ms |
24392 KB |
Output is correct |
9 |
Correct |
25 ms |
24392 KB |
Output is correct |
10 |
Correct |
28 ms |
24392 KB |
Output is correct |
11 |
Correct |
30 ms |
81308 KB |
Output is correct |
12 |
Correct |
61 ms |
81308 KB |
Output is correct |
13 |
Correct |
62 ms |
81308 KB |
Output is correct |
14 |
Correct |
66 ms |
81308 KB |
Output is correct |
15 |
Correct |
87 ms |
81308 KB |
Output is correct |
16 |
Correct |
55 ms |
81308 KB |
Output is correct |
17 |
Correct |
30 ms |
81308 KB |
Output is correct |
18 |
Correct |
33 ms |
81308 KB |
Output is correct |
19 |
Correct |
61 ms |
81308 KB |
Output is correct |
20 |
Correct |
63 ms |
81308 KB |
Output is correct |
21 |
Execution timed out |
4051 ms |
81308 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
24012 KB |
Output is correct |
3 |
Correct |
24 ms |
24088 KB |
Output is correct |
4 |
Correct |
22 ms |
24088 KB |
Output is correct |
5 |
Correct |
22 ms |
24136 KB |
Output is correct |
6 |
Correct |
24 ms |
24392 KB |
Output is correct |
7 |
Correct |
22 ms |
24392 KB |
Output is correct |
8 |
Correct |
23 ms |
24392 KB |
Output is correct |
9 |
Correct |
25 ms |
24392 KB |
Output is correct |
10 |
Correct |
28 ms |
24392 KB |
Output is correct |
11 |
Correct |
549 ms |
41432 KB |
Output is correct |
12 |
Correct |
1085 ms |
51220 KB |
Output is correct |
13 |
Correct |
1205 ms |
64136 KB |
Output is correct |
14 |
Correct |
1255 ms |
64136 KB |
Output is correct |
15 |
Correct |
1255 ms |
64136 KB |
Output is correct |
16 |
Correct |
1418 ms |
81308 KB |
Output is correct |
17 |
Correct |
1053 ms |
81308 KB |
Output is correct |
18 |
Correct |
1167 ms |
81308 KB |
Output is correct |
19 |
Correct |
1294 ms |
81308 KB |
Output is correct |
20 |
Correct |
715 ms |
81308 KB |
Output is correct |
21 |
Correct |
30 ms |
81308 KB |
Output is correct |
22 |
Correct |
61 ms |
81308 KB |
Output is correct |
23 |
Correct |
62 ms |
81308 KB |
Output is correct |
24 |
Correct |
66 ms |
81308 KB |
Output is correct |
25 |
Correct |
87 ms |
81308 KB |
Output is correct |
26 |
Correct |
55 ms |
81308 KB |
Output is correct |
27 |
Correct |
30 ms |
81308 KB |
Output is correct |
28 |
Correct |
33 ms |
81308 KB |
Output is correct |
29 |
Correct |
61 ms |
81308 KB |
Output is correct |
30 |
Correct |
63 ms |
81308 KB |
Output is correct |
31 |
Execution timed out |
4051 ms |
81308 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |