# -*- coding: utf8 -*- # import math from typing import List
deftrace_path(vec, pathes): ifnot vec: return pathes valid_pathes = [] for item in vec[0]: for path in pathes: if item > path[-1]: valid_pathes.append([*path, item])
defget_all_valid_path(vec: List[List[int]]) -> List[List[int]]: ifnot vec: return [] for v in vec: ifnot v: return [] return trace_path(vec=vec[1:], pathes=[[i] for i in vec[0]])