图
涛涛酱
北邮研究僧在读
展开
-
【面试题】判断图中是否有环
无向图 求出图中所有顶点的度; 删除图中所有度≤1的顶点且与该顶点相关的边,把与这些边相关的顶点的度-1; 如果还有度≤1的顶点,重复步骤2; 如果最后还存在未被删除的顶点,表示有环,否则无环。 有向图 计算图中所有点的入度,把入度为0的点加入栈; 如果栈非空: 取出栈顶顶点a,输出该顶点值删除该顶点; 从图中删除所有以a为起始点的边,如果删除过程中遇到另一个顶点入度为0,则把它入栈; ...转载 2020-04-12 13:19:08 · 656 阅读 · 0 评论 -
【LeetCode 1334】 Find the City With the Smallest Number of Neighbors at a Threshold Distance
题目描述 There are n cities numbered from 0 to n-1. Given the array edges where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the in...原创 2020-02-16 14:37:55 · 181 阅读 · 0 评论