#include "bits/stdc++.h"
using namespace std;
long long n;
vector< vector<long long> > Grafo;
vector<long long> Visitados;
void Init(int N_) {
n = (long long)N_;
Grafo.assign(n, vector<long long>());
}
void Link(int A, int B){
long long a = (long long)A;
long long b = (long long)B;
Grafo[a].push_back(b);
Grafo[b].push_back(a);
}
int Bien;
long long Ciclos;
void DFS(long long Nodo, long long Anterior){
Visitados[Nodo] = 1;
long long c = 0;
for(auto E: Grafo[Nodo]){
if(Visitados[E] == 1) c++;
if(Visitados[E] == 1 and E != Anterior){
Bien = 0;
}
if(Visitados[E] == 0){
DFS(E, Nodo);
c++;
}
}
if(c >= 3){
Bien = 0;
}
}
int CountCritical(){
int r = 0;
vector<long long> Buenos;
for(long long i = 0; i < n; i++){
if(Grafo[i].size() >= 4){
Bien = 1;
Visitados.assign(n, 0);
Visitados[i] = 2;
for(long long j = 0; j < n; j++){
if(i == j) continue;
if(Visitados[j] == 0){
DFS(j, -2);
}
}
return Bien;
}
}
bool Solo_4 = 0;
for(long long i = 0; i < n; i++){
if(Grafo[i].size() == 3){
Buenos.push_back(i);
for(auto E: Grafo[i]){
Buenos.push_back(E);
}
Solo_4 = 1;
break;
}
}
if(Solo_4){
for(auto i: Buenos){
Bien = 1;
Visitados.assign(n, 0);
Visitados[i] = 2;
for(long long j = 0; j < n; j++){
if(i == j) continue;
if(Visitados[j] == 0){
DFS(j, -2);
}
}
r += Bien;
}
} else {
Ciclos = 0;
Visitados.assign(n, 0);
long long Ciclado;
for(long long i = 0; i < n; i++){
if(!Visitados[i]){
Bien = 1;
DFS(i, -2);
if(Bien == 0) Bien = 1;
else Bien = 0;
Ciclos += Bien;
if(Bien == 1) Ciclado = i;
}
}
if(Ciclos > 1) return 0;
else if(Ciclos == 1){
set<long long> Tenemos;
while(1){
if(Tenemos.find(Ciclado) != Tenemos.end()) break;
r++;
Tenemos.insert(Ciclado);
long long a = Grafo[Ciclado][0], b = Grafo[Ciclado][1];
if(Tenemos.count(a) == 0) Ciclado = a;
else Ciclado = b;
}
} else {
return (int)n;
}
}
return r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
1104 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
246 ms |
33020 KB |
Output is correct |
2 |
Correct |
484 ms |
50504 KB |
Output is correct |
3 |
Correct |
549 ms |
75672 KB |
Output is correct |
4 |
Correct |
620 ms |
63236 KB |
Output is correct |
5 |
Correct |
694 ms |
64800 KB |
Output is correct |
6 |
Correct |
1033 ms |
107292 KB |
Output is correct |
7 |
Correct |
578 ms |
73412 KB |
Output is correct |
8 |
Correct |
1326 ms |
59208 KB |
Output is correct |
9 |
Correct |
1529 ms |
63516 KB |
Output is correct |
10 |
Correct |
618 ms |
64900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
1104 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
10 ms |
592 KB |
Output is correct |
12 |
Correct |
23 ms |
1380 KB |
Output is correct |
13 |
Correct |
36 ms |
1352 KB |
Output is correct |
14 |
Correct |
11 ms |
1016 KB |
Output is correct |
15 |
Correct |
16 ms |
1104 KB |
Output is correct |
16 |
Correct |
19 ms |
1040 KB |
Output is correct |
17 |
Correct |
56 ms |
948 KB |
Output is correct |
18 |
Correct |
29 ms |
1524 KB |
Output is correct |
19 |
Correct |
19 ms |
1084 KB |
Output is correct |
20 |
Correct |
57 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
1104 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
10 ms |
592 KB |
Output is correct |
12 |
Correct |
23 ms |
1380 KB |
Output is correct |
13 |
Correct |
36 ms |
1352 KB |
Output is correct |
14 |
Correct |
11 ms |
1016 KB |
Output is correct |
15 |
Correct |
16 ms |
1104 KB |
Output is correct |
16 |
Correct |
19 ms |
1040 KB |
Output is correct |
17 |
Correct |
56 ms |
948 KB |
Output is correct |
18 |
Correct |
29 ms |
1524 KB |
Output is correct |
19 |
Correct |
19 ms |
1084 KB |
Output is correct |
20 |
Correct |
57 ms |
1108 KB |
Output is correct |
21 |
Execution timed out |
4062 ms |
2432 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
1104 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
246 ms |
33020 KB |
Output is correct |
12 |
Correct |
484 ms |
50504 KB |
Output is correct |
13 |
Correct |
549 ms |
75672 KB |
Output is correct |
14 |
Correct |
620 ms |
63236 KB |
Output is correct |
15 |
Correct |
694 ms |
64800 KB |
Output is correct |
16 |
Correct |
1033 ms |
107292 KB |
Output is correct |
17 |
Correct |
578 ms |
73412 KB |
Output is correct |
18 |
Correct |
1326 ms |
59208 KB |
Output is correct |
19 |
Correct |
1529 ms |
63516 KB |
Output is correct |
20 |
Correct |
618 ms |
64900 KB |
Output is correct |
21 |
Correct |
10 ms |
592 KB |
Output is correct |
22 |
Correct |
23 ms |
1380 KB |
Output is correct |
23 |
Correct |
36 ms |
1352 KB |
Output is correct |
24 |
Correct |
11 ms |
1016 KB |
Output is correct |
25 |
Correct |
16 ms |
1104 KB |
Output is correct |
26 |
Correct |
19 ms |
1040 KB |
Output is correct |
27 |
Correct |
56 ms |
948 KB |
Output is correct |
28 |
Correct |
29 ms |
1524 KB |
Output is correct |
29 |
Correct |
19 ms |
1084 KB |
Output is correct |
30 |
Correct |
57 ms |
1108 KB |
Output is correct |
31 |
Execution timed out |
4062 ms |
2432 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |