import
java.util.ArrayList;
import
java.util.HashSet;
import
java.util.List;
import
java.util.Set;
public
class
Main {
public
static
List<Integer> subtract(List<Integer> A, List<Integer> B) {
List<Integer> result =
new
ArrayList<>(A);
result.removeAll(B);
return
result;
}
public
static
List<Integer> intersect(List<Integer> A, List<Integer> B) {
List<Integer> result =
new
ArrayList<>(A);
result.retainAll(B);
return
result;
}
public
static
List<Integer> unite(List<Integer> A, List<Integer> B) {
Set<Integer> unionSet =
new
HashSet<>(A);
unionSet.addAll(B);
return
new
ArrayList<>(unionSet);
}
public
static
String inconsistentlyWeightedObject(
int
N,
int
Q, List<List<List<Integer>>> comparisons) {
List<Integer> potentialCandidates =
new
ArrayList<>();
List<Integer> objectNotCompared =
new
ArrayList<>();
for
(
int
i =
0
; i < N; ++i) {
potentialCandidates.add(i +
1
);
objectNotCompared.add(i +
1
);
}
for
(List<List<Integer>> c : comparisons) {
if
(c.get(
1
).get(
0
) ==
'='
) {
potentialCandidates = subtract(potentialCandidates, unite(c.get(
0
), c.get(
2
)));
}
else
{
potentialCandidates = intersect(potentialCandidates, (c.get(
1
).get(
0
) ==
'>'
) ? c.get(
2
) : c.get(
0
));
}
objectNotCompared = subtract(objectNotCompared, unite(c.get(
0
), c.get(
2
)));
}
if
(potentialCandidates.size() ==
1
) {
return
Integer.toString(potentialCandidates.get(
0
));
}
else
if
(potentialCandidates.isEmpty()) {
if
(objectNotCompared.size() ==
1
) {
return
Integer.toString(objectNotCompared.get(
0
));
}
else
{
return
"Insufficient data"
;
}
}
else
{
return
"Insufficient data"
;
}
}
public
static
void
main(String[] args) {
int
N =
6
;
int
Q =
3
;
List<List<List<Integer>>> comparisons =
new
ArrayList<>();
comparisons.add(List.of(List.of(
1
,
2
), List.of((
int
)
'='
), List.of(
5
,
6
)));
comparisons.add(List.of(List.of(
1
,
2
,
3
), List.of((
int
)
'>'
), List.of(
4
,
5
,
6
)));
comparisons.add(List.of(List.of(
3
,
4
), List.of((
int
)
'<'
), List.of(
5
,
6
)));
System.out.println(inconsistentlyWeightedObject(N, Q, comparisons));
}
}