forked from MiYazJE/Acepta-el-reto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp212.java
48 lines (33 loc) · 1.02 KB
/
p212.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.*;
/**
* @author Rubén Saiz
*/
public class p212 {
static boolean caminoEuleriano(int[] vertices, int max) {
int impares = 0;
for (int i = 1; i < max; i++) {
if (vertices[i] % 2 != 0) impares++;
if (impares > 2) return false;
}
return true;
}
public static void main(String[] args) {
final Scanner s = new Scanner(System.in);
int[] vertices = new int[1000];
int A, B;
int intersecciones, calles;
while (true) {
calles = s.nextInt();
if (calles == 0) break;
intersecciones = s.nextInt();
for (int i = 1; i <= intersecciones; i++)
vertices[i] = 0;
for (int i = 0; i < calles; i++) {
A = s.nextInt();
B = s.nextInt();
vertices[A]++; vertices[B]++;
}
System.out.println( caminoEuleriano(vertices, intersecciones) ? "SI" : "NO" );
}
}
}