哈希
134. 报文回路
import java.util.Scanner;
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int count = Integer.parseInt(in.nextLine());
Map<Integer, List<Integer>> map = new HashMap<>();
for (int i = 0; i < count; i++) {
String[] split = in.nextLine().split(" ");
int key = Integer.parseInt(split[0]);
int value = Integer.parseInt(split[1]);
List<Integer> orDefault = map.getOrDefault(key, new ArrayList<>());
orDefault.add(value);
map.put(key, orDefault);
}
for (Integer integer : map.keySet()) {
List<Integer> list = map.get(integer);
for (Integer integer1 : list) {
if (!map.containsKey(integer1)){
System.out.println("False");
return;
}
List<Integer> list1 = map.get(integer1);
for (Integer integer2 : list1) {
if (!map.containsKey(integer2) || !list1.contains(integer)){
System.out.println("False");
return;
}
}
}
}
System.out.println("True");
}
}
标签:map,key,int,System,split,哈希,Integer
From: https://www.cnblogs.com/aclq/p/17713903.html