-
Notifications
You must be signed in to change notification settings - Fork 0
/
P520.java
55 lines (33 loc) · 940 Bytes
/
P520.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
49
50
51
52
53
54
55
package aceptaelreto;
import java.util.Scanner;
import java.util.ArrayList;
public class p520 {
static Scanner s;
static ArrayList<Integer> init(int nCubes){
ArrayList<Integer> cubes = new ArrayList<Integer>();
for(int i = 1; i<= nCubes;i++) {
cubes.add(i);
}
return cubes;
}
public static void main(String args[]) {
s = new Scanner(System.in);
ArrayList<Integer> cubes;
int ncubes,bol,cube1,cube2,aux;
while(true) {
ncubes = s.nextInt();
bol = s.nextInt();
if(ncubes == 0 && bol == 0)break;
cubes = init(ncubes);
while(true) {
cube1 = s.nextInt();
cube2 = s.nextInt();
if(cube1 == 0 && cube2 == 0)break;
aux = cubes.get(cube1-1);
cubes.set(cube1-1, cubes.get(cube2-1));
cubes.set(cube2-1, aux);
}
System.out.println(cubes.indexOf(bol)+1);
}
}
}