We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- BFS: Shortest Reach in a Graph
- Discussions
BFS: Shortest Reach in a Graph
BFS: Shortest Reach in a Graph
Sort by
recency
|
310 Discussions
|
Please Login in order to post a comment
include
include
include
include
include
include
using namespace std;
class Graph { vector> adjList; int n;
};
"each node is labeled from 1 to n", this is in the first sentence of the description and also shown in the examples, however after spending hours to debug, I found out that in the main() function, it is decrementing the node's label so that it is actually labeled from 0 to n-1.
I just want to point this out, hopefully it will be helpful. This is for C++.
int main() { ...... // read and set edges for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--, v--; // add each edge to the graph graph.add_edge(u, v); } int startId; cin >> startId; startId--; // Find shortest reach from node s vector distances = graph.shortest_reach(startId);
Python
Kotlin code
JAva code