Solved! Leetcode 1319. Number of Operations to Make Network Connected

source: https://leetcode.com/problems/number-of-operations-to-make-network-connected/description/ Table of ContentsNumber of Operations to Make Network ConnectedDescriptionExample 1:Example 2:Example 3:Constraints:Solution Number of Operations to Make Network Connected Description There are n computers numbered from 0 to n – 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a connection between computers ai and bi. Any ...

Solved! Leetcode 1466. Reorder Routes to Make All Paths Lead to the City Zero

source: https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/description/ Reorder Routes to Make All Paths Lead to the City Zero There are n cities numbered from 0 to n – 1 and n – 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to ...

Solved! Leetcode 2492. Minimum Score of a Path Between Two Cities

source: https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/ Minimum Score of a Path Between Two Cities You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai and bi with a distance equal ...

Solved! Leetcode 2359: Find Closest Node to Given Two Nodes

You are given a directed graph of n nodes numbered from 0 to n – 1, where each node has at most one outgoing edge. The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no ...

Leetcode 1519: Number of Nodes in the Sub-Tree With the Same Label

You are given a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case character given in the string labels (i.e., The node with the number i has the label labels[i]). The edges array is given ...

Leetcode 1443: Minimum Time to Collect All Apples in a Tree

Given an undirected tree consisting of n vertices numbered from 0 to n-1, which has some apples in their vertices. You spend 1 second to walk over one edge of the tree. Return the minimum time in seconds you have to spend to collect all apples in the tree, starting at vertex 0 and coming back to this vertex. The edges of the ...

Leetcode 797: All Paths From Source to Target

Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order. The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]). https://leetcode.com/problems/all-paths-from-source-to-target/description/ class Solution { public List<List<Integer>> allPathsSourceTarget(int[][] ...

Detect Cycle in a Directed Graph 1

Title: Detect Cycle in a Directed Graph Source: www.geeksforgeeks.org Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least one cycle, else return false. For example, the following graph contains three cycles 0->2->0, 0->1->2->0 and 3->3, so your function must ...