I’m trying to implement the program which can return all the connected parts of a scattered graph as a 2D vector array. here is the code i wrote : #include <bits/stdc++.h> using namespace std; typedef long long int ll; void checkConnected(int** edges, int n, int s,int* visited, vector<int> &v) { v.push_back(s); visited[s] = 1; for(int ..

#### Category : graph

This question is built off of this other question. Assuming I have a stable junction algorithm implemented. I am trying to derive a graph from the junctions. I am stuck on: How do I move along a line in openCV and calculate the path length? So for example when evaluating point C: C connects with: ..

I have a directed graph. Initially, all nodes are assumed to be unvisited and flag is -1 in vector<int>flag. Now we start from a source node & push into stack<int>s and make flag[source]=0 . Now I do DFS traversal & push nodes if(flag[node]==-1)& make flag[node]=0. if all the DFS directed links are visited I pop ..

I am trying to detect the cycle in a directed graph. Initially, I have assumed all nodes to be unvisited and have their value as -1 in vector<int>flag. Now we start from a source node and push into stack<int>s and make flag[source]=0 as it is present in stack. Now I will do the DFS traversal ..

class graph{ void DFSutil(int v); public: map<int, vector<int> > adj; map<int, bool> visited; map<int, int> color; int twoteams = 1; void DFS(); void addEdge(int u,int v); }; this function adds edge to the graph void graph::addEdge(int u,int v){ adj[u].push_back(v); } depth first search function. i tried to color the child as !parent (in case im ..

I tried to write an algorithm that returns the shortest path in an unweighted graph for source s and target t. It takes in a .txt file to build the adjacency list and then logs the length of the path and the path itself on the console. It works for many test cases but for ..

I am recently working with BFS algorithm. I made a maze solving program with this algorithm. here is my code: #include<iostream> #include<cmath> #include<sstream> #include<vector> #include<queue> #include <unistd.h> using namespace std; int m,n; inline int indexFor(int x,int y) { return (x-1) + m*(y-1); } int main() { FILE *file = fopen("test_case","r"); // test_case file //build maze ..

Given a tree and Q queries to be answered. In each query you will be provided with 2 nodes u & v. You should return the path, like u -> v1 -> v2… -> v I have a naive approach to perform DFS for each query but can it be made any better? Is any ..

So, consider the following graph,where ‘this means weight’ 1–‘2’–2–‘5′–5 |’1’ ‘4’ /’1′ src=1 and destination =5 | / Therefore, output = 1+3+1=5 4–‘3′—–3 So my question is can i use bsf instead of dijkstra’s ,since int the tutorial that i am following said that we cannot use the bsf for weighted graph so we have ..

I’m using the Lemon C++ library for graphs, and what I need to do is to find all the paths between two nodes. I’m able to find a single path (the shortest), but I need all of them. Is there a way to achieve this with Lemon? // Create the graph ListDigraph g; ListDigraph::Node a ..

## Recent Comments