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.
I don't understand the answer to the first query for the sample input; the value (number of coprime edges in the path from node 4 to node 6) is shown as 9, but I don't see how it can be any value greater than 5. Here's my thinking:
1. It says the graph is undirected, connected, with nEdges = nNodes - 1.
2. This means the graph is a tree (acyclic) so there is a unique path between nodes.
3. The maximum length of a shortest path between two nodes can't exceed the number of edges, which is 5.
What's going on?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Coprime Paths
You are viewing a single comment's thread. Return to all comments →
I don't understand the answer to the first query for the sample input; the value (number of coprime edges in the path from node 4 to node 6) is shown as 9, but I don't see how it can be any value greater than 5. Here's my thinking: 1. It says the graph is undirected, connected, with nEdges = nNodes - 1. 2. This means the graph is a tree (acyclic) so there is a unique path between nodes. 3. The maximum length of a shortest path between two nodes can't exceed the number of edges, which is 5. What's going on?