-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhoIsTaller.java
79 lines (70 loc) · 2.19 KB
/
whoIsTaller.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Classz20;
import java.util.*;
/**
*
* @author moyangwang
*/
public class whoIsTaller {
public static void print (ArrayList<Integer>[]arr){
for(int i = 0; i<arr.length;i++){
System.out.println(i+" "+arr[i]);
}
System.out.println();
}
public static void main (String []args){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
ArrayList<Integer>[] taller = new ArrayList[n+1];
ArrayList<Integer>[] shorter = new ArrayList[n+1];
for(int i = 0; i<=n; i++){
taller[i]=new ArrayList();
shorter[i]=new ArrayList();
}
for (int i = 0; i<m; i++){
int a = input.nextInt();
int b = input.nextInt();
ArrayList<Integer> first = new ArrayList();
ArrayList<Integer> second = new ArrayList();
for(int u = 0; u<shorter[b].size();u++){
int l = shorter[b].get(u);
taller[l].add(a);
shorter[a].add(l);
}
for(int u = 0; u<taller[a].size();u++){
int l = taller[a].get(u);
shorter[l].add(b);
taller[b].add(l);
}
shorter[a].add(b);
taller[b].add(a);
}
int a = input.nextInt();
int b = input.nextInt();
boolean bool = false;
for(int i = 0; i<taller[a].size(); i++){
if (taller[a].get(i)==b){
bool = true;
System.out.println("no");
break;
}
}
if (!bool){
for (int i = 0; i<shorter[a].size(); i++){
if (shorter[a].get(i)==b){
bool = true;
System.out.println("yes");
break;
}
}
}
if(!bool){
System.out.println("unknown");
}
}
}