adj
to represent the graph.q
and add node 1
to it.visit
array to keep track of visited nodes.answer
with the maximum possible value.answer
with the minimum of the current answer
and the edge weight.
d. If the connected node is not visited, mark it as visited and add it to the queue.answer
as the result.