[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-86366-en":3,"doc-seo-86366-105":29,"detail-sidebar-cat-0-en-105":90},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":4,"is_deleted":4,"is_public":20,"is_downloadable":20,"audit_status":20,"page_count":21,"language":22,"language_code":23,"site_id":24,"html_lang":23,"table_of_contents":25,"faqs":26,"seo_title":13,"seo_description":14,"update_tm":27,"read_time":28},86366,549758146520,"Patrick","https://ap-avatar.wpscdn.com/avatar/80002397d8c0411e94?_k=1775819394049821470",8,"Research & Report","A Polynomial-Time Algorithm for the Next-to-Shortest Path Problem on Positively Weighted Directed Graphs","The next-to-shortest path problem, given a directed graph with terminals s and t, seeks a simple s→t path that is shortest among all not-shortest s→t paths, if such a path exists. Introduced in 1996 and shown NP-complete for non-negative weights, it remained open for strictly positive weights. This work resolves the longstanding question by designing the first polynomial-time algorithm for directed graphs with positive edge weights, including an explicit runtime bound and constructive output.","A Polynomial-Time Algorithm for the Next-to-Shortest Path Problem on Positively Weighted Directed Graphs  \nKuowen Chen∗ IIIS, Tsinghua University  \nNicole Wein† University of Michigan  \nYiran Zhang‡ IIIS, Tsinghua University  \narXiv :2511 .04345v2 [ cs .DS] 13 Jul 2026  \nAbstract  \nGiven a graph and a pair of terminals s, t, the next-to-shortest path problem asks for an s→t (simple) path that is shortest among all not shortest s→t paths (if one exists) . This problem was introduced in 1996, and soon after was shown to be NP-complete for directed graphs with non-negative edge weights, leaving open the case of positive edge weights. Subsequent work investigated this open question, and developed polynomial-time algorithms for the cases ofundirected graphs and planar directed graphs. In this work, we resolve this nearly 30-yearold open problem by providing an algorithm for the next-to-shortest path problem on directed graphs with positive edge weights.  \n∗ This work was initiated while the author was at the University [of Michigan.](of Michigan. ckw22@mails.tsinghua.edu.cn)[ ckw22@mails.tsinghua.edu.cn](of Michigan. ckw22@mails.tsinghua.edu.cn)[ ](of Michigan. ckw22@mails.tsinghua.edu.cn)†[nswein@umich.edu](nswein@umich.edu)  \n‡[zhangyir22@mails.tsinghua.edu.cn](zhangyir22@mails.tsinghua.edu.cn)  \n1 Introduction  \nGiven a directed graph with positive edge weights, and a pair of terminals s, t, the next-to-shortest path problem (also known as the strictly second-shortest path problem) asks for an s→t (simple) path that is shortest among all not shortest s → t paths (if one exists) . We present the first polynomial time algorithm for this problem.  \nThe next-to-shortest path problem was first introduced by Lalgudi, Papaefthyrniou, and Potkonjak in 1996 for the application of processing data streams in hardware [LPP96, LPP00] . Soon after, Lalgudi and Papaefthymiou proved that the problem is NP-complete on directed graphs with nonnegative edge weights [LP97], but that there is a polynomial-time algorithm for the relaxation where the path need not be simple. In their NP-hardness reduction, the weight-0 edges play a crucial role, and the case of positive edge weights remained open for almost 30 years until the present work. In the meantime there was a long line of work on the next-to-shortest path problem in undirected graphs.  \nIn 2004, Krasikov and Noble gave the first polynomial-time algorithm for the undirected nextto-shortest path problem with positive edge weights [KN04] . (They also conjectured that it is NP-complete for directed graphs; we disprove this conjecture if P  NP.) For an n-vertex, m-edge graph, their algorithm ran in time O (n3 m) time, and was subsequently improved by Li, Sun, and Chen to O(n3 ) [LSC06], then by Kao, Chang, Wang, and Juan to O(n2 ) [KCWJ11], and finally by Wu to O(nlog n+m) with the additional guarantee that the path can be found in linear time if the distances from s and t to all other vertices have already been computed [Wu13] . This was extended to non-negative edge weights by Wu, Guo, and Wang [WGW12](see also independent work by Zhang and Nagamochi with larger running time [ZN12]) . Before the general solution was known, the problem was also studied on special classes of graphs [MP06, BMP09] . See also [DHLS14] for a data structure that implicitly represents near-shortest s-t paths. Additionally, the problem of finding an induced not-shortest path is also solvable in polynomial time on unweighted graphs [BSS21] .  \nFor directed graphs with positive edge weights, Wu and Wang gave a polynomial-time algorithm of the next-to-shortest path problem when the graph is planar [WW15] . They also proved some properties of a solution for general positively weighted directed graphs. However no further progress was made, and in fact, it was not even known how to find any not-shortest s→t path in polynomial time.  \nAt least 11 papers have explicitly stated the open problem solved in this paper:  \nIs the next-","cbCaimAQf2AFXFTn","https://ap.wps.com/l/cbCaimAQf2AFXFTn","pdf",1270076,1,34,"English","en",105,"# Introduction\n## Our Contribution\n## Related Work","[{\"question\":\"What is the next-to-shortest path problem in this paper?\",\"answer\":\"Given a directed graph and terminals s, t, it asks for a simple s→t path that is the shortest among all s→t paths that are not shortest (if such a path exists). The paper also notes it is known as the strictly second-shortest path problem.\"},{\"question\":\"Why was the case of positive edge weights challenging?\",\"answer\":\"Lalgudi, Papaefthyrniou, and Potkonjak introduced the problem in 1996, and NP-completeness was shown for directed graphs with non-negative edge weights. The positive edge weights case remained open for nearly 30 years until this work.\"},{\"question\":\"What does the main result provide?\",\"answer\":\"The paper gives a polynomial-time algorithm that determines whether a next-to-shortest path from s to t exists and, if so, outputs such a path. It states an explicit time complexity bound in Theorem 1.1.\"}]",1784210999,86,{"code":4,"msg":30,"data":31},"ok",{"site_id":24,"language":23,"slug":32,"title":13,"keywords":33,"description":14,"schema_data":34,"social_meta":85,"head_meta":87,"extra_data":89,"updated_unix":27},"a-polynomial-time-algorithm-for-the-next-to-shortest-path-problem-on-positively-weighted-directed-graphs","",{"@graph":35,"@context":84},[36,53,67],{"@type":37,"itemListElement":38},"BreadcrumbList",[39,43,47,50],{"item":40,"name":41,"@type":42,"position":20},"https://docshare.wps.com","Home","ListItem",{"item":44,"name":45,"@type":42,"position":46},"https://docshare.wps.com/document/","Document",2,{"item":48,"name":12,"@type":42,"position":49},"https://docshare.wps.com/document/research-report/",3,{"item":51,"name":13,"@type":42,"position":52},"https://docshare.wps.com/document/a-polynomial-time-algorithm-for-the-next-to-shortest-path-problem-on-positively-weighted-directed-graphs/86366/",4,{"url":51,"name":13,"@type":54,"author":55,"headline":13,"publisher":57,"fileFormat":60,"inLanguage":23,"description":14,"dateModified":61,"datePublished":61,"encodingFormat":60,"isAccessibleForFree":62,"interactionStatistic":63},"DigitalDocument",{"name":9,"@type":56},"Person",{"url":40,"name":58,"@type":59},"DocShare","Organization","application/pdf","2026-07-16",true,{"@type":64,"interactionType":65,"userInteractionCount":4},"InteractionCounter",{"@type":66},"ViewAction",{"@type":68,"mainEntity":69},"FAQPage",[70,76,80],{"name":71,"@type":72,"acceptedAnswer":73},"What is the next-to-shortest path problem in this paper?","Question",{"text":74,"@type":75},"Given a directed graph and terminals s, t, it asks for a simple s→t path that is the shortest among all s→t paths that are not shortest (if such a path exists). The paper also notes it is known as the strictly second-shortest path problem.","Answer",{"name":77,"@type":72,"acceptedAnswer":78},"Why was the case of positive edge weights challenging?",{"text":79,"@type":75},"Lalgudi, Papaefthyrniou, and Potkonjak introduced the problem in 1996, and NP-completeness was shown for directed graphs with non-negative edge weights. The positive edge weights case remained open for nearly 30 years until this work.",{"name":81,"@type":72,"acceptedAnswer":82},"What does the main result provide?",{"text":83,"@type":75},"The paper gives a polynomial-time algorithm that determines whether a next-to-shortest path from s to t exists and, if so, outputs such a path. It states an explicit time complexity bound in Theorem 1.1.","https://schema.org",{"og:url":51,"og:type":86,"og:title":13,"og:site_name":58,"og:description":14},"article",{"robots":88,"canonical":51},"index,follow",{"doc_id":7,"site_id":24},{"code":4,"msg":5,"data":91},[92,96,100,104,109,114,119,122,127,130,134],{"id":20,"doc_module":4,"doc_module_name":45,"category_name":93,"show_sort_weight":94,"slug":95},"Story & Novel",90,"story-novel",{"id":46,"doc_module":4,"doc_module_name":45,"category_name":97,"show_sort_weight":98,"slug":99},"Literature",80,"literature",{"id":52,"doc_module":4,"doc_module_name":45,"category_name":101,"show_sort_weight":102,"slug":103},"Exam",70,"exam",{"id":105,"doc_module":4,"doc_module_name":45,"category_name":106,"show_sort_weight":107,"slug":108},5,"Comic",60,"comic",{"id":110,"doc_module":4,"doc_module_name":45,"category_name":111,"show_sort_weight":112,"slug":113},6,"Technology",50,"technology",{"id":115,"doc_module":4,"doc_module_name":45,"category_name":116,"show_sort_weight":117,"slug":118},7,"Healthcare",40,"healthcare",{"id":11,"doc_module":4,"doc_module_name":45,"category_name":12,"show_sort_weight":120,"slug":121},30,"research-report",{"id":123,"doc_module":4,"doc_module_name":45,"category_name":124,"show_sort_weight":125,"slug":126},9,"Religion & Spirituality",20,"religion-spirituality",{"id":125,"doc_module":4,"doc_module_name":45,"category_name":128,"show_sort_weight":125,"slug":129},"World Cup","world-cup",{"id":131,"doc_module":4,"doc_module_name":45,"category_name":132,"show_sort_weight":131,"slug":133},10,"Lifestyle","lifestyle",{"id":135,"doc_module":4,"doc_module_name":45,"category_name":136,"show_sort_weight":105,"slug":137},19,"General","general"]