Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
971 views
in Technique[技术] by (71.8m points)

graph - How to check u-v can be arbitrarily negative length using Floyd Warshall algorithm?

If i have q query [start, end] in the graph. How to check whether:

the length of start to end can be arbitrarily negative length?

0  floydWarshall(matrix, n) // RUN THE FLOYD WARSHALL ALGORITHM
1  FOR (start, end) in q:
2  check = false
2  while(start != end)
3     start = Next(start)
4     if (dist[start][start] < 0)
5          check = true, break
6  if check == true
7     return "Negative Loop here"

I try the code like above and get Time limit because I have a while loop inside which is to find negative loop in the path from start to end.

Can you help me find another method?

question from:https://stackoverflow.com/questions/65862296/how-to-check-u-v-can-be-arbitrarily-negative-length-using-floyd-warshall-algorit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...