### sequenceReconstruction 
from collections import deque
from collections import defaultdict
from typing import *
def f_gold(org: List[int], seqs: List[List[int]]) -> bool:
    n = len(org)
    nums = set()
    for seq in seqs:
        for num in seq:
            if num < 1 or num > n:
                return False
            nums.add(num)
    if len(nums) < n:
        return False
    edges = defaultdict(list)
    indegree = [0] * (n + 1)
    for seq in seqs:
        i = seq[0]
        for j in seq[1:]:
            edges[i].append(j)
            indegree[j] += 1
            i = j
    q = deque()
    for i in range(1, n + 1):
        if indegree[i] == 0:
            q.append(i)
    cnt = 0
    while q:
        if len(q) > 1 or org[cnt] != q[0]:
            return False
        i = q.popleft()
        cnt += 1
        for j in edges[i]:
            indegree[j] -= 1
            if indegree[j] == 0:
                q.append(j)
    return cnt == n