(int[] parent)
| 4 | private final Map<Integer, List<Integer>> child; |
| 5 | |
| 6 | public LockingTree(int[] parent) { |
| 7 | this.parent = parent; |
| 8 | locked = new int[parent.length]; |
| 9 | child = new HashMap<>(); |
| 10 | |
| 11 | for (int i = 0; i < parent.length; i++) { |
| 12 | child.putIfAbsent(parent[i], new ArrayList<>()); |
| 13 | child.putIfAbsent(i, new ArrayList<>()); |
| 14 | child.get(parent[i]).add(i); |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | public boolean lock(int num, int user) { |
| 19 | if (locked[num] <= 0) { |