File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -485,6 +485,45 @@ if __name__ == "__main__":
485485
486486### Javascript
487487
488+ ``` js
489+ async function main () {
490+ // 輸入
491+ const rl = require (' readline' ).createInterface ({ input: process .stdin })
492+ const iter = rl[Symbol .asyncIterator ]()
493+ const readline = async () => (await iter .next ()).value
494+ const [n , m ] = (await readline ()).split (" " ).map (Number )
495+ const edges = []
496+ for (let i = 0 ; i < m ; i++ ) {
497+ edges .push ((await readline ()).split (" " ).map (Number ))
498+ }
499+ const minDist = Array .from ({length: n + 1 }, () => Number .MAX_VALUE )
500+ // 起始點
501+ minDist[1 ] = 0
502+
503+ for (let i = 1 ; i < n ; i++ ) {
504+ let update = false
505+ for (const [src , desc , w ] of edges) {
506+ if (minDist[src] !== Number .MAX_VALUE && minDist[src] + w < minDist[desc]) {
507+ minDist[desc] = minDist[src] + w
508+ update = true
509+ }
510+ }
511+ if (! update) {
512+ break ;
513+ }
514+ }
515+
516+ // 輸出
517+ if (minDist[n] === Number .MAX_VALUE ) {
518+ console .log (' unconnected' )
519+ } else {
520+ console .log (minDist[n])
521+ }
522+ }
523+
524+ main ()
525+ ```
526+
488527### TypeScript
489528
490529### PhP
You can’t perform that action at this time.
0 commit comments