/*
public class RandomListNode {
    int label;
    RandomListNode next = null;
    RandomListNode random = null;

    RandomListNode(int label) {
        this.label = label;
    }
}
*/
import java.util.HashMap;
import java.util.Map;
public class Solution {
    public Map<RandomListNode, RandomListNode> map = new HashMap<>();
    public RandomListNode Clone(RandomListNode pHead) {
        if(pHead == null) {
            return null;
        }
        if(!map.containsKey(pHead)) {
            RandomListNode head = new RandomListNode(pHead.label);
            map.put(pHead, head);
            head.next = Clone(pHead.next);
            head.random = Clone(pHead.random);
            return head;
        }
        return map.get(pHead);
    }
}