图是树的升级版。图通常分为有向(directed)或无向(undirected),有循环(cyclic)或无循环(acyclic),所有节点相连(connected)或不相连(disconnected)。
图通常有两种表示方法。假设图中一共有n 个节点、m 条边。
二分图算法也称为染色法,是一种广度优先搜索。如果可以用两种颜色对图中的节点进行着
色,并且保证相邻的节点颜色不同,那么图为二分。
LeetCode-785. Is Graph Bipartite? [C++][Java]_贫道绝缘子的博客-CSDN博客There is anundirectedgraph withnnodes, where each node is numbered between0andn - 1. You are given a 2D arraygraph, wheregraph[u]is an array of nodes that nodeuis adjacent to. More formally, for eachvingraph[u], there is an undirected edge b...https://blog.csdn.net/qq_15711195/article/details/126397821?spm=1001.2014.3001.5502LeetCode-207. Course Schedule [C++][Java]_贫道绝缘子的博客-CSDN博客There are a total ofnumCoursescourses you have to take, labeled from0tonumCourses - 1. You are given an arrayprerequisiteswhereprerequisites[i] = [ai, bi]indicates that youmusttake coursebifirst if you want to take courseai. reuturn true .......https://blog.csdn.net/qq_15711195/article/details/126416977?spm=1001.2014.3001.5502LeetCode-210. Course Schedule II [C++][Java]_贫道绝缘子的博客-CSDN博客There are a total ofnumCoursescourses you have to take, labeled from0tonumCourses - 1. You are given an arrayprerequisiteswhereprerequisites[i] = [ai, bi]indicates that youmusttake coursebifirst if you want to take courseai.https://blog.csdn.net/qq_15711195/article/details/126416918?spm=1001.2014.3001.5502LeetCode-1059. All Paths from Source Lead to Destination [C++][Java]_贫道绝缘子的博客-CSDN博客Given the edges of a directed graph, and two nodes source and destination of this graph, determine whether or not all paths starting from source eventually end at destination,this problem is pretty straight forward.https://blog.csdn.net/qq_15711195/article/details/126435369?spm=1001.2014.3001.5502LeetCode-1135. Connecting Cities With Minimum Cost [C++][Java]_贫道绝缘子的博客-CSDN博客Return the minimum cost so that for every pair of cities, there exists a pathof connections (possibly of length 1) that connects those two cities together. The cost is the sum of the connection costs used. If the task is impossible, return -1.https://blog.csdn.net/qq_15711195/article/details/126447763?spm=1001.2014.3001.5502LeetCode-882. Reachable Nodes In Subdivided Graph [C++][Java]_贫道绝缘子的博客-CSDN博客In thisnew graph, you want to know how many nodes arereachablefrom the node0, where a node isreachableif the distance ismaxMovesor less.Given the original graph andmaxMoves, returnthe number of nodes that arereachablefrom node0in the new grhttps://blog.csdn.net/qq_15711195/article/details/126455402?spm=1001.2014.3001.5502LeetCode-684. Redundant Connection [C++][Java]_贫道绝缘子的博客-CSDN博客You are given a graph that started as a tree withnnodes labeled from1ton, with one additional edge added. The added edge has twodifferentvertices chosen from1ton, and was not an edge that already existed. The graph is represented as an arrayedgehttps://blog.csdn.net/qq_15711195/article/details/126456032?spm=1001.2014.3001.5502