you give direct weighted graph n node 2n2 edge the node label 1 n edge label 1 2n2 the graph edge split part the n1 edge form root span tree node 1 root all edge point away root the n1 edge node node 1 2 in you give q query there type query 1 w Change weight ith edge w 2 u v Print length short path node u v give query print short path length