Avatar

Organizations

3 results for 拓扑排序
  • 给定一个  m x n 整数矩阵  matrix ,找出其中 最长递增路径 的长度。

    对于每个单元格,你可以往上,下,左,右四个方向移动。 你 不能对角线 方向上移动或移动到 边界外(即不允许环绕)。

  • A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.

    Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges where edges[i] = [ai, bi] indicates that there is an undirected edge between the two nodes ai and bi in the tree, you can choose any node of the tree as the root. When you select a node x as the root, the result tree has height h. Among all possible rooted trees, those with minimum height (i.e. min(h))  are called minimum height trees (MHTs).

    Return a list of all MHTs’ root labels. You can return the answer in any order.

    The height of a rooted tree is the number of edges on the longest downward path between the root and a leaf.

  • You are given an array pairs, where \(pairs[i] = [x_i, y_i]\), and:

    • There are no duplicates.
    • \(x_i < y_i\)

    Let ways be the number of rooted trees that satisfy the following conditions:

    • The tree consists of nodes whose values appeared in pairs.
    • A pair \([x_i, y_i]\) exists in pairs if and only if \(x_i\) is an ancestor of \(y_i\) or \(y_i\) is an ancestor of \(x_i\).
    • Note: the tree does not have to be a binary tree.

    Two ways are considered to be different if there is at least one node that has different parents in both ways.

    Return:

    • 0 if ways == 0
    • 1 if ways == 1
    • 2 if ways > 1

    A rooted tree is a tree that has a single root node, and all edges are oriented to be outgoing from the root.

    An ancestor of a node is any node on the path from the root to that node (excluding the node itself). The root has no ancestors.

    leetcode 困难 拓扑排序 Created Wed, 16 Feb 2022 12:23:57 +0800