-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHackerRank8.htm
executable file
·1178 lines (938 loc) · 160 KB
/
HackerRank8.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html style="--font-family-text:OpenSans; --font-family-input:SourceCodePro;" lang="en-us"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title> HackerRank </title><meta name="description" id="meta-description" content="Join over 2 million developers in solving code challenges on HackerRank, one of the best ways to prepare for programming interviews."><meta property="og:title" id="meta-og-title" content="HackerRank"><meta property="og:image" id="meta-og-image" content="https://hrcdn.net/og/default.jpg"><meta property="og:description" id="meta-og-description" content="Join over 2 million developers in solving code challenges on HackerRank, one of the best ways to prepare for programming interviews."><meta property="og:url" content="https://www.hackerrank.com/challenges/dijkstrashortreach/problem"><meta property="og:site_name" content="HackerRank"><meta property="og:type" id="meta-og-type" content="website"><meta property="article:author" content="https://www.facebook.com/hackerrank"><meta name="twitter:card" content="summary"><meta name="twitter:site" content="@hackerrank"><meta name="twitter:url" content="https://www.hackerrank.com/challenges/dijkstrashortreach/problem"><meta name="twitter:title" id="meta-twitter-title" content="HackerRank"><meta property="fb:app_id" content="347499128655783"><meta content="authenticity_token" name="csrf-param" id="csrf-param"><meta content="3ESxscGBc03Wsm94zz5G1os1/4EpqNFc1F/RCPOUpGNYK6vj5z1BCxpohToN+65oeghx6HQ/gUCGzwFtAWiuWQ==" name="csrf-token" id="csrf-token">
<script data-cfasync="false" charset="UTF-8" src="HackerRank8_files/ef.js"></script><script data-cfasync="false" charset="UTF-8" src="HackerRank8_files/ec.js"></script><script type="text/javascript" async="" src="HackerRank8_files/mixpanel-2-latest.htm"></script><script type="text/javascript" async="" src="HackerRank8_files/ga.js"></script><script>/*!
* JavaScript Cookie v2.1.3
* https://github.com/js-cookie/js-cookie
*
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
* Released under the MIT license
*/
;(function (factory) {
var registeredInModuleLoader = false;
if (typeof define === 'function' && define.amd) {
define(factory);
registeredInModuleLoader = true;
}
if (typeof exports === 'object') {
module.exports = factory();
registeredInModuleLoader = true;
}
if (!registeredInModuleLoader) {
var OldCookies = window.Cookies;
var api = window.Cookies = factory();
api.noConflict = function () {
window.Cookies = OldCookies;
return api;
};
}
}(function () {
function extend () {
var i = 0;
var result = {};
for (; i < arguments.length; i++) {
var attributes = arguments[ i ];
for (var key in attributes) {
result[key] = attributes[key];
}
}
return result;
}
function init (converter) {
function api (key, value, attributes) {
var result;
if (typeof document === 'undefined') {
return;
}
// Write
if (arguments.length > 1) {
attributes = extend({
path: '/'
}, api.defaults, attributes);
if (typeof attributes.expires === 'number') {
var expires = new Date();
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
attributes.expires = expires;
}
try {
result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {}
if (!converter.write) {
value = encodeURIComponent(String(value))
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
} else {
value = converter.write(value, key);
}
key = encodeURIComponent(String(key));
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
key = key.replace(/[\(\)]/g, escape);
return (document.cookie = [
key, '=', value,
attributes.expires ? '; expires=' + attributes.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
attributes.path ? '; path=' + attributes.path : '',
attributes.domain ? '; domain=' + attributes.domain : '',
attributes.secure ? '; secure' : ''
].join(''));
}
// Read
if (!key) {
result = {};
}
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling "get()"
var cookies = document.cookie ? document.cookie.split('; ') : [];
var rdecode = /(%[0-9A-Z]{2})+/g;
var i = 0;
for (; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var cookie = parts.slice(1).join('=');
if (cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);
}
try {
var name = parts[0].replace(rdecode, decodeURIComponent);
cookie = converter.read ?
converter.read(cookie, name) : converter(cookie, name) ||
cookie.replace(rdecode, decodeURIComponent);
if (this.json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}
if (key === name) {
result = cookie;
break;
}
if (!key) {
result[name] = cookie;
}
} catch (e) {}
}
return result;
}
api.set = api;
api.get = function (key) {
return api.call(api, key);
};
api.getJSON = function () {
return api.apply({
json: true
}, [].slice.call(arguments));
};
api.defaults = {};
api.remove = function (key, attributes) {
api(key, '', extend(attributes, {
expires: -1
}));
};
api.withConverter = init;
return api;
}
return init(function () {});
}));
</script>
<style>
.cdn-error-view {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: white;
z-index: 9999;
font-family: "Whitney SSm A", "Whitney SSm B", "Avenir", "Segoe UI", "Ubuntu", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.cdn-error-view .error-box-wrap {
position: absolute;
top: 50%;
left: 50%;
padding: 20px;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
text-align: center;
}
.cdn-error-view .error-icon {
text-align: center;
}
.cdn-error-view .error-title {
font-size: 48px;
margin-top: 30px;
margin-bottom: 0;
font-weight: bold;
}
.cdn-error-view .error-message {
margin-top: 20px;
margin-bottom: 0;
}
.cdn-error-view .btn-wrap {
margin-top: 20px;
}
.cdn-error-view .btn-reload {
width: 300px;
padding: 10px;
border-radius: 3px;
border-color: #088837;
border-bottom-color: #007827;
border-width: 1px;
border-style: solid;
color : #FFF;
background-color: #2ec866;
background-image: -webkit-gradient(linear, top left, bottom left, color-stop(0, #2ec866), color-stop(1, #29b35b));
background-image: -webkit-linear-gradient(top, #2ec866, #29b35b);
background-image: linear-gradient(top, #2ec866, #29b35b);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), inset 0 1px 1px rgba(255, 255, 255, 0.1), inset 0 -1px 4px rgba(32, 138, 70, 0.3);
outline: none;
}
</style>
<script>
var cdnLoaded = false;
var checkForWorkingCDN = (function() {
//this two value should come from configuration
var cdns = ["hrcdn.net","d3keuzeb2crhkn.cloudfront.net"];
var cdnUrl = Cookies.get('cdn_url') || cdns[0];
var filePath = "https://hrcdn.net/hackerrank/assets/cdnping-d8824f325f64e103a04a4582006560a7.js";
//extract pathname from url
var urlRegex = /^[^#]*?:\/\/.*?(\/.*)$/ ;
var match = filePath.match(urlRegex);
if(match) filePath = match[1];
//add current cdn on first of array
cdns.splice(cdns.indexOf(cdnUrl), 1);
cdns.unshift(cdnUrl);
var cdnIndx = 0;
function tryCurrentCDN() {
if (cdnUrl) document.write('<script src="https://' + cdnUrl + filePath + '?' + Date.now() + '"><\/script>');
document.write('<script>checkForWorkingCDN();<\/script>');
}
//try the current cdn
tryCurrentCDN();
return function() {
if (cdnUrl && cdnLoaded) {
Cookies.set('cdn_url', cdnUrl, {expires: 3});
Cookies.set('cdn_set', 'true', {expires: 3});
if (cdnIndx !== 0) {
document.location.reload();
}
//if cdnUrl not loaded check the next cdn;
} else if (cdnUrl) {
//track all the failed cdn
var failedCdns = Cookies.get('failed_cdn_hosts');
if (failedCdns) {
failedCdns = JSON.parse(failedCdns);
} else {
failedCdns = [];
}
failedCdns.push(cdnUrl);
var fifteenMinuteFromNow = new Date();
fifteenMinuteFromNow.setMinutes(15);
Cookies.set('failed_cdn_hosts', JSON.stringify(failedCdns), {expires: fifteenMinuteFromNow});
Cookies.set("cdn_url_switched", "true", {expires: fifteenMinuteFromNow});
//try next cdn
cdnIndx += 1;
cdnUrl = cdns[cdnIndx];
tryCurrentCDN();
//if no cdn left to check and none of loaded return err
} else {
Cookies.remove('cdn_url');
return 'cdnerror';
}
}
}());
</script><script src="HackerRank8_files/cdnping-d8824f325f64e103a04a4582006560a7.js"></script><script>checkForWorkingCDN();</script>
<script>
//track cdn related matrices
(function() {
var allCdns = ["hrcdn.net","d3keuzeb2crhkn.cloudfront.net"];
var metrics = [];
var defaultCdn = Cookies.get('default_cdn_url');
//method to track the events
function appTrack(key, attrs) {
attrs = attrs || {};
attrs.uid = Cookies.get('hackerrank_mixpanel_token')
metrics.push({
'key': key,
'meta_data': attrs
});
}
function sendMetrices() {
if (!XMLHttpRequest) return;
var xhr = new XMLHttpRequest();
var metrics_endpoint = 'https://metrics.hackerrank.com/app_metrics'; // Todo : this need to move on configuration
if (!xhr) return;
xhr.open("POST", metrics_endpoint, true);
//set xhr headers and options
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.withCredentials = true;
xhr.send(JSON.stringify({
data: metrics,
default_cdn_url: defaultCdn,
document_referrer: document.referrer
}));
}
var cdnUrl = Cookies.get('cdn_url');
var failedCdns = Cookies.get('failed_cdn_hosts');
var cdnMetrices = {};
//track used cdn host
if (cdnUrl) {
cdnMetrices['used-cdn'] = cdnUrl;
cdnMetrices['cdn-index'] = allCdns.indexOf(cdnUrl) + 1;
cdnMetrices['all-failed'] = false;
//track if all cdn failed (If cdnUrl is not set it means all cdn url failed)
} else {
cdnMetrices['used-cdn'] = '';
cdnMetrices['cdn-index'] = 999;
cdnMetrices['all-failed'] = true;
}
appTrack('cdn-metrices', cdnMetrices);
//track failed cdn
if (failedCdns) {
failedCdns = JSON.parse(failedCdns);
Cookies.remove('failed_cdn_hosts');
failedCdns.forEach(function(cdn) {
appTrack('failed-cdn-host', {
cdn: cdn
});
});
}
//send metrics
sendMetrices();
}());
</script>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="icon" type="image/png" href="https://hrcdn.net/hackerrank/assets/favicon-679803bc95e4e83ded7b9726f98795b2.png">
<!-- Prefetch / preload dns and assets on production -->
<link rel="dns-prefetch" href="https://hrcdn.net/">
<link rel="dns-prefetch" href="https://d3keuzeb2crhkn.cloudfront.net/">
<link rel="dns-prefetch" href="https://notifications.hackerrank.com/">
<link rel="dns-prefetch" href="https://api.mixpanel.com/">
<link rel="dns-prefetch" href="https://heapanalytics.com/">
<link rel="dns-prefetch" href="https://metrics.hackerrank.com/">
<link rel="preconnect" href="https://sentry.io/">
<link rel="dns-prefetch" href="https://sentry.io/">
<!-- Prefetch old assets -->
<link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank-ea25ee40710ea64eba5a625f01efdb82.js">
<link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/base-6ce2506955bc38544d364c5628a7cf46.js">
<link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_libraries-98dea744b3ae35b454e41a097f276d65.js">
<!-- Prefetch old assets end-->
<!-- preload scripts required on the same page -->
<link rel="preload" as="script" href="HackerRank8_files/hackerrank_r_vendor-4966df136c.js">
<link rel="preload" as="script" href="HackerRank8_files/hackerrank_r_common-27f87a97d6303aeff8c0.js">
<link rel="preload" as="script" href="HackerRank8_files/hackerrank_r_app-c82782ffcb1c5c932a5f.js">
<link rel="preload" as="script" href="HackerRank8_files/hackerrank_r_community-e8b13deda13c9533154b.js">
<link rel="preload" as="script" href="HackerRank8_files/hackerrank_r_challenge-62369df05b7279036344.js">
<!-- preload scripts end -->
<!-- preload font files -->
<!-- Preload font file end -->
<!-- Prefetch old css files -->
<link rel="prefetch" href="HackerRank8_files/hackerrank-core-e96f7a6cfef052d65475f24f3b7f204a.css">
<link rel="prefetch" href="HackerRank8_files/hackerrank_libraries-fa8929ae336cf0e420d48cce368af2d0.css">
<link rel="prefetch" href="HackerRank8_files/dashboard-7a8a1c56a67dc807300c9fc417514ed1.css">
<!-- Prefetch old css files end -->
<link href="HackerRank8_files/hackerrank_libraries-fa8929ae336cf0e420d48cce368af2d0.css" media="all" rel="stylesheet"><link rel="stylesheet" href="HackerRank8_files/hackerrank_libraries-fa8929ae336cf0e420d48cce368af2d0.css">
<link href="HackerRank8_files/hackerrank-core-e96f7a6cfef052d65475f24f3b7f204a.css" media="all" rel="stylesheet">
<link href="HackerRank8_files/dashboard-7a8a1c56a67dc807300c9fc417514ed1.css" media="all" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="HackerRank8_files/hackerrank_r_app-ebafff4fbe.css">
<link rel="stylesheet" href="HackerRank8_files/hackerrank_r_community-b949defbb1.css">
<!-- Load promise polyfill for the non-believers -->
<script>
window.Promise || document.write('<script src="https://hrcdn.net/hackerrank/assets/promise-polyfill/promise.min-633a04f76540d9de7f7b468be4396133.js" type="text\/javascript"><\/script>');
</script>
<style>
html.scroll-hidden,html.scroll-hidden body{
overflow: hidden;
height:100vh;
}
html.scroll-hidden.pad-adjustment body{
padding-right : 17px;
}
html.scroll-hidden.pad-adjustment .fixed-elm{
padding-right : 17px;
}
</style>
<script type="text/javascript" charset="utf-8" async="" src="HackerRank8_files/hackerrank_r_community-e8b13deda13c9533154b.js"></script><script src="HackerRank8_files/container.js" data-cfasync="false" async="true" defer="true" data-vendor="userty" data-role="container" charset="utf-8"></script><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_challenge_list_v2-f72a64e383fc56d166e1.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_hackerlevel-88d861a9f45caedd4a8b.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_challenge_list-62802914fb34b5fe267d.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_contest-ec25cda400bb8f0d9664.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_dashboardv2-82b16a83230f3ec9069e.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_dashboard-bfe6a789d3d24c1d4a76.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_rank-c263ff63bd2b62c01248.js"><link rel="prefetch" href="HackerRank8_files/hackerrank_r_codeshell_lib-e6962ca44c2864fa175e.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_leaderboard-9d9dcaa7033cf35f29c8.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_jobs-db6c0132fa3e038d764c.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_profile-f5f10e6820aa1bc20764.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_calendar-c94786944cd226558f42.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_code_snippets-c279e3b2cac4c07804ee.js"><link rel="prefetch" href="https://hrcdn.net/hackerrank/assets/hackerrank_r_onboarding-27802227e5ac1c221c4d.js"><script type="text/javascript" charset="utf-8" async="" src="HackerRank8_files/hackerrank_r_challenge-62369df05b7279036344.js"></script><title><!-- react-text: 3 --> <!-- /react-text --><!-- react-text: 4 -->HackerRank<!-- /react-text --><!-- react-text: 5 --> <!-- /react-text --></title><style id="react-tooltip">.__react_component_tooltip{border-radius:3px;display:inline-block;font-size:13px;left:-999em;opacity:0;padding:8px 21px;position:fixed;pointer-events:none;transition:opacity 0.3s ease-out;top:-999em;visibility:hidden;z-index:999}.__react_component_tooltip:before,.__react_component_tooltip:after{content:"";width:0;height:0;position:absolute}.__react_component_tooltip.show{opacity:0.9;margin-top:0px;margin-left:0px;visibility:visible}.__react_component_tooltip.type-dark{color:#fff;background-color:#222}.__react_component_tooltip.type-dark.place-top:after{border-top-color:#222;border-top-style:solid;border-top-width:6px}.__react_component_tooltip.type-dark.place-bottom:after{border-bottom-color:#222;border-bottom-style:solid;border-bottom-width:6px}.__react_component_tooltip.type-dark.place-left:after{border-left-color:#222;border-left-style:solid;border-left-width:6px}.__react_component_tooltip.type-dark.place-right:after{border-right-color:#222;border-right-style:solid;border-right-width:6px}.__react_component_tooltip.type-dark.border{border:1px solid #fff}.__react_component_tooltip.type-dark.border.place-top:before{border-top:8px solid #fff}.__react_component_tooltip.type-dark.border.place-bottom:before{border-bottom:8px solid #fff}.__react_component_tooltip.type-dark.border.place-left:before{border-left:8px solid #fff}.__react_component_tooltip.type-dark.border.place-right:before{border-right:8px solid #fff}.__react_component_tooltip.type-success{color:#fff;background-color:#8DC572}.__react_component_tooltip.type-success.place-top:after{border-top-color:#8DC572;border-top-style:solid;border-top-width:6px}.__react_component_tooltip.type-success.place-bottom:after{border-bottom-color:#8DC572;border-bottom-style:solid;border-bottom-width:6px}.__react_component_tooltip.type-success.place-left:after{border-left-color:#8DC572;border-left-style:solid;border-left-width:6px}.__react_component_tooltip.type-success.place-right:after{border-right-color:#8DC572;border-right-style:solid;border-right-width:6px}.__react_component_tooltip.type-success.border{border:1px solid #fff}.__react_component_tooltip.type-success.border.place-top:before{border-top:8px solid #fff}.__react_component_tooltip.type-success.border.place-bottom:before{border-bottom:8px solid #fff}.__react_component_tooltip.type-success.border.place-left:before{border-left:8px solid #fff}.__react_component_tooltip.type-success.border.place-right:before{border-right:8px solid #fff}.__react_component_tooltip.type-warning{color:#fff;background-color:#F0AD4E}.__react_component_tooltip.type-warning.place-top:after{border-top-color:#F0AD4E;border-top-style:solid;border-top-width:6px}.__react_component_tooltip.type-warning.place-bottom:after{border-bottom-color:#F0AD4E;border-bottom-style:solid;border-bottom-width:6px}.__react_component_tooltip.type-warning.place-left:after{border-left-color:#F0AD4E;border-left-style:solid;border-left-width:6px}.__react_component_tooltip.type-warning.place-right:after{border-right-color:#F0AD4E;border-right-style:solid;border-right-width:6px}.__react_component_tooltip.type-warning.border{border:1px solid #fff}.__react_component_tooltip.type-warning.border.place-top:before{border-top:8px solid #fff}.__react_component_tooltip.type-warning.border.place-bottom:before{border-bottom:8px solid #fff}.__react_component_tooltip.type-warning.border.place-left:before{border-left:8px solid #fff}.__react_component_tooltip.type-warning.border.place-right:before{border-right:8px solid #fff}.__react_component_tooltip.type-error{color:#fff;background-color:#BE6464}.__react_component_tooltip.type-error.place-top:after{border-top-color:#BE6464;border-top-style:solid;border-top-width:6px}.__react_component_tooltip.type-error.place-bottom:after{border-bottom-color:#BE6464;border-bottom-style:solid;border-bottom-width:6px}.__react_component_tooltip.type-error.place-left:after{border-left-color:#BE6464;border-left-style:solid;border-left-width:6px}.__react_component_tooltip.type-error.place-right:after{border-right-color:#BE6464;border-right-style:solid;border-right-width:6px}.__react_component_tooltip.type-error.border{border:1px solid #fff}.__react_component_tooltip.type-error.border.place-top:before{border-top:8px solid #fff}.__react_component_tooltip.type-error.border.place-bottom:before{border-bottom:8px solid #fff}.__react_component_tooltip.type-error.border.place-left:before{border-left:8px solid #fff}.__react_component_tooltip.type-error.border.place-right:before{border-right:8px solid #fff}.__react_component_tooltip.type-info{color:#fff;background-color:#337AB7}.__react_component_tooltip.type-info.place-top:after{border-top-color:#337AB7;border-top-style:solid;border-top-width:6px}.__react_component_tooltip.type-info.place-bottom:after{border-bottom-color:#337AB7;border-bottom-style:solid;border-bottom-width:6px}.__react_component_tooltip.type-info.place-left:after{border-left-color:#337AB7;border-left-style:solid;border-left-width:6px}.__react_component_tooltip.type-info.place-right:after{border-right-color:#337AB7;border-right-style:solid;border-right-width:6px}.__react_component_tooltip.type-info.border{border:1px solid #fff}.__react_component_tooltip.type-info.border.place-top:before{border-top:8px solid #fff}.__react_component_tooltip.type-info.border.place-bottom:before{border-bottom:8px solid #fff}.__react_component_tooltip.type-info.border.place-left:before{border-left:8px solid #fff}.__react_component_tooltip.type-info.border.place-right:before{border-right:8px solid #fff}.__react_component_tooltip.type-light{color:#222;background-color:#fff}.__react_component_tooltip.type-light.place-top:after{border-top-color:#fff;border-top-style:solid;border-top-width:6px}.__react_component_tooltip.type-light.place-bottom:after{border-bottom-color:#fff;border-bottom-style:solid;border-bottom-width:6px}.__react_component_tooltip.type-light.place-left:after{border-left-color:#fff;border-left-style:solid;border-left-width:6px}.__react_component_tooltip.type-light.place-right:after{border-right-color:#fff;border-right-style:solid;border-right-width:6px}.__react_component_tooltip.type-light.border{border:1px solid #222}.__react_component_tooltip.type-light.border.place-top:before{border-top:8px solid #222}.__react_component_tooltip.type-light.border.place-bottom:before{border-bottom:8px solid #222}.__react_component_tooltip.type-light.border.place-left:before{border-left:8px solid #222}.__react_component_tooltip.type-light.border.place-right:before{border-right:8px solid #222}.__react_component_tooltip.place-top{margin-top:-10px}.__react_component_tooltip.place-top:before{border-left:10px solid transparent;border-right:10px solid transparent;bottom:-8px;left:50%;margin-left:-10px}.__react_component_tooltip.place-top:after{border-left:8px solid transparent;border-right:8px solid transparent;bottom:-6px;left:50%;margin-left:-8px}.__react_component_tooltip.place-bottom{margin-top:10px}.__react_component_tooltip.place-bottom:before{border-left:10px solid transparent;border-right:10px solid transparent;top:-8px;left:50%;margin-left:-10px}.__react_component_tooltip.place-bottom:after{border-left:8px solid transparent;border-right:8px solid transparent;top:-6px;left:50%;margin-left:-8px}.__react_component_tooltip.place-left{margin-left:-10px}.__react_component_tooltip.place-left:before{border-top:6px solid transparent;border-bottom:6px solid transparent;right:-8px;top:50%;margin-top:-5px}.__react_component_tooltip.place-left:after{border-top:5px solid transparent;border-bottom:5px solid transparent;right:-6px;top:50%;margin-top:-4px}.__react_component_tooltip.place-right{margin-left:10px}.__react_component_tooltip.place-right:before{border-top:6px solid transparent;border-bottom:6px solid transparent;left:-8px;top:50%;margin-top:-5px}.__react_component_tooltip.place-right:after{border-top:5px solid transparent;border-bottom:5px solid transparent;left:-6px;top:50%;margin-top:-4px}.__react_component_tooltip .multi-line{display:block;padding:2px 0px;text-align:center}</style><script type="text/javascript" charset="utf-8" async="" src="HackerRank8_files/hackerrank_r_codeshell_lib-e6962ca44c2864fa175e.js"></script><script src="HackerRank8_files/codemirror_basic-bffb4505db599846f31efa96739b4605.js" async=""></script><script data-cfasync="false" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="//cdn.userty.com/235-hackerrankcomcommunity/feedback/userty.feedback.js?v=0.1.9" src="HackerRank8_files/userty_008.js"></script><script data-cfasync="false" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="//cdn.userty.com/235-hackerrankcomcommunity/record/userty.record.js?v=0.1.9" src="HackerRank8_files/userty_003.js"></script><script data-cfasync="false" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="//cdn.userty.com/235-hackerrankcomcommunity/visualEditorLoader/userty.visualeditorloader.js?v=0.1.9" src="HackerRank8_files/userty_006.js"></script><script data-cfasync="false" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="//cdn.userty.com/235-hackerrankcomcommunity/core/userty.api.js?v=0.1.9" src="HackerRank8_files/userty_002.js"></script><script data-cfasync="false" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="//cdn.userty.com/235-hackerrankcomcommunity/core/userty.utils.js?v=0.1.9" src="HackerRank8_files/userty.js"></script><script data-cfasync="false" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="//cdn.userty.com/235-hackerrankcomcommunity/core/userty.behavior.js?v=0.1.9" src="HackerRank8_files/userty_007.js"></script><script src="HackerRank8_files/clike-e8a662bb29372d98371ad2d9a65ee349.js" async=""></script><script data-cfasync="false" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="//cdn.userty.com/235-hackerrankcomcommunity/feedback/userty.templates.default.js?v=0.1.9" src="HackerRank8_files/userty_005.js"></script><script data-cfasync="false" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="//cdn.userty.com/235-hackerrankcomcommunity/core/userty.m.js?v=0.1.9" src="HackerRank8_files/userty_004.js"></script></head>
<body id="hr_v2">
<div class="cdn-error-view" style="display:none;">
<div class="error-box-wrap">
<div class="error-icon">
<svg x="0px" y="0px" width="80px" height="80px" viewBox="0 0 367.011 367.01" style="enable-background:new 0 0 367.011 367.01;" xml:space="preserve">
<g>
<g>
<path d="M365.221,329.641L190.943,27.788c-1.542-2.674-4.395-4.318-7.479-4.318c-3.084,0-5.938,1.645-7.48,4.318L1.157,330.584 c-1.543,2.674-1.543,5.965,0,8.639c1.542,2.674,4.395,4.318,7.48,4.318h349.65c0.028,0,0.057,0,0.086,0 c4.77,0,8.638-3.863,8.638-8.639C367.011,332.92,366.342,331.1,365.221,329.641z M23.599,326.266L183.464,49.381l159.864,276.885 H23.599z"></path>
<path d="M174.826,136.801v123.893c0,4.773,3.867,8.638,8.638,8.638c4.77,0,8.637-3.863,8.637-8.638V136.801 c0-4.766-3.867-8.637-8.637-8.637C178.693,128.165,174.826,132.036,174.826,136.801z"></path>
<path d="M183.464,279.393c-5.922,0-10.725,4.8-10.725,10.722s4.803,10.729,10.725,10.729c5.921,0,10.725-4.809,10.725-10.729 C194.189,284.193,189.386,279.393,183.464,279.393z"></path>
</g>
</g>
</svg>
</div>
<h2 class="error-title">Something went wrong!</h2>
<p class="error-message">Some error occured while loading page for you. Please try again.</p>
<div class="btn-wrap">
<a href="#" onclick="window.location.reload(true);"><button class="btn-reload">Reload</button></a>
</div>
</div>
</div>
<script>
if(typeof cdnLoaded !== 'undefined' && cdnLoaded === false){
document.querySelector('.cdn-error-view').style.display = 'block';
}
</script>
<div id="fb-root"></div>
<!-- Just a placeholder div to start loading open sans and source code loader -->
<div class="font-open-sans-loader"></div>
<div class="font-source-code-loader"></div>
<!-- Just a placeholder div to start loading open sans and source code loader end -->
<div id="content" onclick="void(0);"><div class="body-wrap community-page challenges-page problem-page" data-reactroot="" data-reactid="1" data-react-checksum="1880920498"><div class="toast-message loading" data-reactid="2"><span class="toast-container containment" data-reactid="3"><i class="ui-icon-loading" data-reactid="4"></i><span class="toast-text" data-reactid="5">Loading...</span></span></div><!-- react-empty: 6 --><div class="component-wrapper" data-reactid="7"><!-- react-empty: 8 --><div class="logged-user" data-reactid="9"><div class="page-header-wrapper" data-reactid="10"><nav class="page-header" data-reactid="11"><div class="container" data-reactid="12"><div class="nav-links header-nav-links" data-reactid="13"><ul class="pull-left nav-links-active" data-reactid="14"><li data-reactid="15"><a class="nav_link backbone logo_mark js_logo_mark" data-analytics="NavBarLogo" href="https://www.hackerrank.com/dashboard" data-reactid="16"><img id="feed-intro" src="HackerRank8_files/h_mark_sm-30dc0e0cbd2dded63b294819ff853a90.svg" alt="" data-reactid="17"></a></li><li data-reactid="18"><a class="nav_link dashboard active" data-analytics="NavBarDomains" href="https://www.hackerrank.com/dashboard" data-reactid="19"><i class="icon-home" data-reactid="20"></i><span data-reactid="21">Practice</span></a></li><li data-reactid="22"><a class="nav_link backbone contests" data-analytics="NavBarContests" href="https://www.hackerrank.com/contests" data-reactid="23"><i class="icon-clock" data-reactid="24"></i><span data-reactid="25">Compete</span></a></li><li data-reactid="26"><a class="nav_link backbone" data-analytics="NavBarJobs" href="https://www.hackerrank.com/jobs" data-reactid="27"><i class="icon-briefcase" data-reactid="28"></i><span data-reactid="29">Jobs</span><i class="icon-circle js-jobs-notification navigation-highlight-icon hidden" data-reactid="30"></i></a></li><li data-reactid="31"><a class="nav_link backbone" data-analytics="NavBarLeaderboard" id="leaderboard-nav-link" href="https://www.hackerrank.com/leaderboard" data-reactid="32"><i class="icon-trophy" data-reactid="33"></i><span data-reactid="34">Leaderboard</span></a></li></ul></div><div class="nav-buttons" data-reactid="35"><ul class="pull-left psR" data-reactid="36"><li class="hide-in-private-contest search-input-container input-icon main-hr-search" id="search-span" data-reactid="37"><div class="search_form" data-reactid="38"><div class="hide-in-private-contest search-input input-icon" data-reactid="39"><div class="search-query asyn-autocomplete autocomplete" data-reactid="40"><div class="ac-input-wrap cf" data-reactid="41"><input autocomplete="off" class="ac-input " data-reactid="42"></div></div><i class="icon-search" data-reactid="43"></i></div></div></li></ul><ul class="pull-left nav-wrap mmL" data-reactid="44"><li class="hide-in-private-contest button-item" data-reactid="45"><div class="dropdown dropdown message-dropdown notify_dropdown" data-reactid="46"><a class="cursor dropdown-handle nav_link hr_nav_messages_link js-dropdown-toggle js-link" data-analytics="NavBarMessageIcon" data-reactid="47"><i class="dropdown-icon icon-chat icon--single" data-reactid="48"></i></a><div class="dropdown-menu large" data-reactid="49"><header class="psT psB text-center menu-header" data-reactid="50"><strong class="header-title" data-reactid="51">Messages</strong></header><div id="notify_messages" class="dropdown-body" data-reactid="52"><div class="hr_nav_messages_list" data-reactid="53"><div class="no-propagation text-center txt-navy empty-msg" data-reactid="54">You have no unread messages.</div></div></div><footer class="final text-center show-all" data-reactid="55"><a class="btn show-all-link" href="https://www.hackerrank.com/inbox" data-analytics="NavBarMessageShowAll" data-reactid="56">Show All</a></footer></div></div></li><li class="button-item" data-reactid="57"><div class="dropdown dropdown notification-dropdown notify_dropdown" data-reactid="58"><a class="cursor dropdown-handle nav_link hr_nav_notifications_link js-dropdown-toggle js-link" data-toggle="dropdown" data-analytics="NavBarNotificationsIcon" data-reactid="59"><i class="dropdown-icon icon-megaphone icon--single" data-reactid="60"></i></a><div class="dropdown-menu large" id="notify_broadcasts" data-reactid="61"><header class="psA menu-header" data-reactid="62"><strong class="header-title" data-reactid="63">Notifications</strong><a class="hr_archive_all archive pull-right js-link" data-analytics="NavBarNotificationsArchiveAll" data-reactid="64"><i class="icon-folder-open" data-reactid="65"></i><!-- react-text: 66 -->Archive All<!-- /react-text --></a></header><div class="clearfix dropdown-body" data-reactid="67"><div class="hr_nav_notifications_list"><ul><li class="notify_item dropdown-item" data-id="56916361" data-category="special-announcement" data-url="https://research.hackerrank.com/developer-skills/2018/"><div class="notification-icon"><img src="HackerRank8_files/notifymarker.png"></div><div class="notification-subject pmT"><div class="psA"><div>Introducing the 2018 Developer Skills Report</div><small class="meta"><time class="time-text" datetime="2018-01-23T15:21:16.000Z" title="2018-01-23 15:21">1 month ago</time></small></div></div></li><li class="notify_item dropdown-item" data-id="50171468" data-category="contest-announcements" data-url="/domains/tutorials/30-days-of-code"><div class="notification-icon"><img src="HackerRank8_files/notifymarker.png"></div><div class="notification-subject pmT"><div class="psA"><div>Improve your coding skills. Join our 30 Days of Code challenge!</div><small class="meta"><time class="time-text" datetime="2017-11-09T16:05:40.000Z" title="2017-11-09 16:05">4 months ago</time></small></div></div></li></ul></div></div><footer class="final show-all" data-reactid="71"><a class="btn show-all-link" href="https://www.hackerrank.com/notifications" data-analytics="NavBarNotificationsShowAll" data-reactid="72">Show All</a></footer></div></div></li><li class="button-item" data-reactid="73"><div class="dropdown dropdown dropdown-auth profile-menu cursor" data-reactid="74"><a class="backbone nav_link js-dropdown-toggle js-link toggle-wrap" data-analytics="NavBarProfileDropDown" data-reactid="75"><img src="HackerRank8_files/gravatar.jpg" alt="" class="avatar" data-reactid="76"><span class="mmR username text-ellipsis" data-reactid="77">a_plasencia</span><i class="icon-down-open" data-reactid="78"></i></a><div class="dropdown-menu drop-list pull-right" data-reactid="79"><ul data-reactid="80"><li class="hide-in-private-contest profile-nav-item" data-reactid="81"><a class="navigation_hackos hackos-count" data-analytics="NavBarProfileDropDownHackos" href="https://www.hackerrank.com/a_plasencia/hackos" data-reactid="82"><!-- react-text: 83 -->Hackos: <!-- /react-text --><span class="navigation_hackos-count" data-reactid="84">121</span></a></li><li class="hide-in-private-contest profile-nav-item" data-reactid="85"><a class="backbone" rel="tooltip" data-placement="left" data-analytics="NavBarProfileDropDownProfile" href="https://www.hackerrank.com/a_plasencia" data-reactid="86"><!-- react-text: 87 -->Profile<!-- /react-text --><div class="ui-progress-bar progress-bar theme-default" data-reactid="88"><div class="progress-filler" style="width:30%;" data-reactid="89"></div></div></a></li><li class="hide-in-private-contest profile-nav-item" data-reactid="90"><a class="backbone" href="https://www.hackerrank.com/settings/profile" data-analytics="NavBarProfileDropDownSettings" data-reactid="91">Settings</a></li><li class="hide-in-private-contest profile-nav-item" data-reactid="92"><a class="backbone" href="https://www.hackerrank.com/challenges/bookmarks" data-analytics="NavBarDropDownBookmarks" data-reactid="93">Saved Challenges</a></li><li class="hide-in-private-contest profile-nav-item" data-reactid="94"><a class="backbone" href="https://www.hackerrank.com/network" data-analytics="NavBarProfileDropDownNetwork" data-reactid="95">Network</a></li><li class="hide-in-private-contest profile-nav-item" data-reactid="96"><a class="backbone" href="https://www.hackerrank.com/submissions" data-analytics="NavBarProfileDropDownSubmissions" data-reactid="97">Submissions</a></li><li class="hide-in-private-contest profile-nav-item" data-reactid="98"><a class="backbone" href="https://www.hackerrank.com/administration" data-analytics="NavBarProfileDropDownAdministration" data-reactid="99">Administration</a></li><li class="profile-nav-item" data-reactid="100"><a class="logout-button js-link" data-analytics="NavBarProfileDropDownLogout" data-reactid="101">Logout</a></li></ul></div></div></li></ul></div></div></nav></div><div id="verifyaccount" class="container" data-reactid="102"><div class="gradient mlT" data-reactid="103"><div class="close close-verification psT psR" data-reactid="104">×</div><div class="message text-center" data-reactid="105"><p class="msB" data-reactid="106">The
email address you signed up with has not been verified. You won't be
ranked on the leaderboard until you verify your account.</p><p style="font-size:13px;" class="action-message" data-reactid="107"><a class="send-verification btn btn-white" data-reactid="108">Re-send the verification email</a></p></div></div></div><div id="breadcrumb" data-reactid="109"><div class="content-header b4" data-reactid="110"><div class="container pjL" data-reactid="111"><div class="d-flex justify-content-between align-items-center" data-reactid="112"><ol itemtype="http://schema.org/BreadcrumbList" class="mdT msB pjT bcrumb" data-reactid="113"><li itemprop="itemListElement" itemtype="http://schema.org/ListItem" data-reactid="114"><a itemprop="item" class="backbone" data-analytics="Breadcrumb" data-attr1="Dashboard" data-attr2="global" data-attr7="1" href="https://www.hackerrank.com/dashboard" data-reactid="115"><span itemprop="name" data-reactid="116">Dashboard</span></a><meta itemprop="position" content="1" data-reactid="117"></li><li itemprop="itemListElement" itemtype="http://schema.org/ListItem" data-reactid="118"><i class="icon-right-open mmL" data-reactid="119"></i><a itemprop="item" class="backbone" data-analytics="Breadcrumb" data-attr1="Algorithms" data-attr2="global" data-attr7="1" href="https://www.hackerrank.com/domains/algorithms" data-reactid="120"><span itemprop="name" data-reactid="121">Algorithms</span></a><meta itemprop="position" content="1" data-reactid="122"></li><li itemprop="itemListElement" itemtype="http://schema.org/ListItem" data-reactid="123"><i class="icon-right-open mmL" data-reactid="124"></i><a itemprop="item" class="backbone" data-analytics="Breadcrumb" data-attr1="Graph Theory" data-attr2="global" data-attr7="1" href="https://www.hackerrank.com/domains/algorithms/graph-theory" data-reactid="125"><span itemprop="name" data-reactid="126">Graph Theory</span></a><meta itemprop="position" content="1" data-reactid="127"></li><li itemprop="itemListElement" itemtype="http://schema.org/ListItem" data-reactid="128"><i class="icon-right-open mmL" data-reactid="129"></i><a itemprop="item" class="backbone" data-analytics="Breadcrumb" data-attr1="Dijkstra: Shortest Reach 2" data-attr2="global" data-attr7="1" href="https://www.hackerrank.com/challenges/dijkstrashortreach" data-reactid="130"><span itemprop="name" data-reactid="131">Dijkstra: Shortest Reach 2</span></a><meta itemprop="position" content="1" data-reactid="132"></li></ol><div class="domain-scores d-flex align-items-center"><div class="badge-progress"><div id="badge-progress" class="mlR js-tooltip "><p class="bold small"><!-- react-text: 330 -->Badge Progress<!-- /react-text --><a rel="tooltip" class="js-details mmL xsmall details-tooltip cursor" data-html="true" data-tip="Earn 150 more points in <strong>Algorithms</strong><br>Earn more points in following sub-domain(s)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Graph Theory</strong>: 20 pts<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Dynamic Programming</strong>: 20 pts<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Sorting</strong>: 20 pts<br>" data-place="bottom" data-analytics="BadgeProgress" currentitem="false">(Details)</a></p><div class="progress-wrapper-domains msT"><span class="progress-bar-domains" style="width: 0%;"></span></div><div class="__react_component_tooltip place-top type-dark " data-id="tooltip"></div></div></div><div class="brcumb-points"><span class="zeta bold">Points: </span><span class="bold domain-score msR">0</span><span class="domain-rank-span"><span class="zeta bold">Rank: </span><span class="bold msR domain-rank ">1122583</span></span></div></div></div></div></div></div><div class="container" data-reactid="134"></div><div class="challenge-view" data-reactid="135"><div class="challenge-header" data-reactid="136"><!-- react-empty: 137 --><div class="container" data-reactid="138"><div class="mdT mmB span10" data-reactid="139"><div class="clearfix" data-reactid="140"><h2 class="hr_tour-challenge-name pull-left mlT" data-reactid="141"><!-- react-text: 142 -->Dijkstra: Shortest Reach 2<!-- /react-text --><i class="icon-bookmark js-bookmark xxsmall txt-grey" data-reactid="143"></i></h2></div><div class="clearfix mlB mmT" data-reactid="144"><img src="HackerRank8_files/gravatar.jpg" class="avatar pull-left" data-reactid="145" width="25" height="25"><span class="small bold" data-reactid="146"><!-- react-text: 147 -->by <!-- /react-text --><a class="backbone color-blue" href="https://www.hackerrank.com/pranav9413" data-analytics="ChallengeViewHeaderAuthor" data-attr1="dijkstrashortreach" data-attr2="pranav9413" data-reactid="148">pranav9413</a></span></div></div></div><div class="container" data-reactid="149"><ul class="nav-tabs nav mlT" data-reactid="150"><li id="problemTab" class="active" data-reactid="151"><a class="hr-problem-link" data-analytics="ChallengeViewTab" data-attr1="/challenges/dijkstrashortreach/problem" data-attr2="Problem" href="https://www.hackerrank.com/challenges/dijkstrashortreach/problem" data-reactid="152">Problem</a></li><li id="submissionsTab" class="" data-reactid="153"><a class="hr-submissions-link" data-analytics="ChallengeViewTab" data-attr1="/challenges/dijkstrashortreach/submissions" data-attr2="Submissions" href="https://www.hackerrank.com/challenges/dijkstrashortreach/submissions" data-reactid="154">Submissions</a></li><li id="leaderboardTab" class="" data-reactid="155"><a class="hr-leaderboard-link" data-analytics="ChallengeViewTab" data-attr1="/challenges/dijkstrashortreach/leaderboard" data-attr2="Leaderboard" href="https://www.hackerrank.com/challenges/dijkstrashortreach/leaderboard" data-reactid="156">Leaderboard</a></li><li id="forumTab" class="" data-reactid="157"><a class="hr-forum-link" data-analytics="ChallengeViewTab" data-attr1="/challenges/dijkstrashortreach/forum" data-attr2="Discussions" href="https://www.hackerrank.com/challenges/dijkstrashortreach/forum" data-reactid="158">Discussions</a></li><li id="editorialTab" class="" data-reactid="159"><a class="hr-editorial-link" data-analytics="ChallengeViewTab" data-attr1="/challenges/dijkstrashortreach/editorial" data-attr2="Editorial" href="https://www.hackerrank.com/challenges/dijkstrashortreach/editorial" data-reactid="160"><!-- react-text: 161 -->Editorial <!-- /react-text --><i class="icon-lock" data-reactid="162"></i></a></li></ul></div></div><section class="challenge-interface challenge-problem" data-reactid="163"><div class="challenge-body" data-reactid="164"><div class="challenge-body-elements-problem challenge-container-element" data-reactid="165"><div class="challenge-split full-screen-split split-wrap" data-reactid="166"><div class="left-pane split" data-reactid="167"><div class="challenge-content" data-reactid="168"><div class="container fs-container" data-reactid="169"><div class="row" data-reactid="170"><div class="span-sm-11 hr_tour-problem-statement problem-statement have-external-links" data-reactid="171"><div class="content-text challenge-text mlB" data-reactid="172"><div class="challenge_problem_statement"><div class="msB challenge_problem_statement_body"><div class="hackdown-content"><style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
</style><svg style="display: none;"><defs id="MathJax_SVG_glyphs"></defs></svg><p>Given a graph consisting <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-1-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="2.064ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 888.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></g></svg></span> nodes (labelled <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-2-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.162ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 500.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></g></svg></span> to <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-3-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="2.064ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 888.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></g></svg></span>) where a specific given node <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-4-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 645.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></g></svg></span> represents the starting position <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-5-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 645.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></g></svg></span> and an edge between two nodes is of a given length, which may or may not be equal to other lengths in the graph. </p>
<p>It is required to calculate the shortest distance from the start position (Node <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-6-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 645.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></g></svg></span>) to all of the other nodes in the graph. </p>
<p><strong>Note:</strong> If a node is unreachable , the distance is assumed as <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-7-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="2.971ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 1279 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path><g transform="translate(778,0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></g></g></svg></span>.</p></div></div></div><div class="challenge_input_format"><div class="msB challenge_input_format_title"><p><strong>Input Format</strong></p></div><div class="msB challenge_input_format_body"><div class="hackdown-content"><style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
</style><svg style="display: none;"><defs id="MathJax_SVG_glyphs"></defs></svg><p>The first line contains <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-1-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.636ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 704.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z"></path></g></svg></span>, denoting the number of test cases. <br>
First line of each test case has two integers <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-2-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="2.064ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 888.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></g></svg></span>, denoting the number of nodes in the graph and <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-3-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="2.442ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 1051.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M289 629Q289 635 232 637Q208 637 201 638T194 648Q194 649 196 659Q197 662 198 666T199 671T201 676T203 679T207 681T212 683T220 683T232 684Q238 684 262 684T307 683Q386 683 398 683T414 678Q415 674 451 396L487 117L510 154Q534 190 574 254T662 394Q837 673 839 675Q840 676 842 678T846 681L852 683H948Q965 683 988 683T1017 684Q1051 684 1051 673Q1051 668 1048 656T1045 643Q1041 637 1008 637Q968 636 957 634T939 623Q936 618 867 340T797 59Q797 55 798 54T805 50T822 48T855 46H886Q892 37 892 35Q892 19 885 5Q880 0 869 0Q864 0 828 1T736 2Q675 2 644 2T609 1Q592 1 592 11Q592 13 594 25Q598 41 602 43T625 46Q652 46 685 49Q699 52 704 61Q706 65 742 207T813 490T848 631L654 322Q458 10 453 5Q451 4 449 3Q444 0 433 0Q418 0 415 7Q413 11 374 317L335 624L267 354Q200 88 200 79Q206 46 272 46H282Q288 41 289 37T286 19Q282 3 278 1Q274 0 267 0Q265 0 255 0T221 1T157 2Q127 2 95 1T58 0Q43 0 39 2T35 11Q35 13 38 25T43 40Q45 46 65 46Q135 46 154 86Q158 92 223 354T289 629Z"></path></g></svg></span>, denoting the number of edges in the graph. </p>
<p>The next <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-4-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="2.442ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 1051.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M289 629Q289 635 232 637Q208 637 201 638T194 648Q194 649 196 659Q197 662 198 666T199 671T201 676T203 679T207 681T212 683T220 683T232 684Q238 684 262 684T307 683Q386 683 398 683T414 678Q415 674 451 396L487 117L510 154Q534 190 574 254T662 394Q837 673 839 675Q840 676 842 678T846 681L852 683H948Q965 683 988 683T1017 684Q1051 684 1051 673Q1051 668 1048 656T1045 643Q1041 637 1008 637Q968 636 957 634T939 623Q936 618 867 340T797 59Q797 55 798 54T805 50T822 48T855 46H886Q892 37 892 35Q892 19 885 5Q880 0 869 0Q864 0 828 1T736 2Q675 2 644 2T609 1Q592 1 592 11Q592 13 594 25Q598 41 602 43T625 46Q652 46 685 49Q699 52 704 61Q706 65 742 207T813 490T848 631L654 322Q458 10 453 5Q451 4 449 3Q444 0 433 0Q418 0 415 7Q413 11 374 317L335 624L267 354Q200 88 200 79Q206 46 272 46H282Q288 41 289 37T286 19Q282 3 278 1Q274 0 267 0Q265 0 255 0T221 1T157 2Q127 2 95 1T58 0Q43 0 39 2T35 11Q35 13 38 25T43 40Q45 46 65 46Q135 46 154 86Q158 92 223 354T289 629Z"></path></g></svg></span> lines each consist of three space-separated integers <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-5-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.33ex" height="1.676ex" style="vertical-align: -0.338ex;" viewBox="0 -576.1 572.5 721.6" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g></svg></span> <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-6-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.155ex" height="2.009ex" style="vertical-align: -0.671ex;" viewBox="0 -576.1 497.5 865.1" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g></svg></span> <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-7-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.049ex" height="1.676ex" style="vertical-align: -0.338ex;" viewBox="0 -576.1 451.5 721.6" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M21 287Q22 290 23 295T28 317T38 348T53 381T73 411T99 433T132 442Q161 442 183 430T214 408T225 388Q227 382 228 382T236 389Q284 441 347 441H350Q398 441 422 400Q430 381 430 363Q430 333 417 315T391 292T366 288Q346 288 334 299T322 328Q322 376 378 392Q356 405 342 405Q286 405 239 331Q229 315 224 298T190 165Q156 25 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 114 189T154 366Q154 405 128 405Q107 405 92 377T68 316T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g></svg></span>, where <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-8-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.33ex" height="1.676ex" style="vertical-align: -0.338ex;" viewBox="0 -576.1 572.5 721.6" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g></svg></span> and <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-9-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.155ex" height="2.009ex" style="vertical-align: -0.671ex;" viewBox="0 -576.1 497.5 865.1" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g></svg></span> denote the two nodes between which the <strong>undirected</strong> edge exists, <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-10-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.049ex" height="1.676ex" style="vertical-align: -0.338ex;" viewBox="0 -576.1 451.5 721.6" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M21 287Q22 290 23 295T28 317T38 348T53 381T73 411T99 433T132 442Q161 442 183 430T214 408T225 388Q227 382 228 382T236 389Q284 441 347 441H350Q398 441 422 400Q430 381 430 363Q430 333 417 315T391 292T366 288Q346 288 334 299T322 328Q322 376 378 392Q356 405 342 405Q286 405 239 331Q229 315 224 298T190 165Q156 25 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 114 189T154 366Q154 405 128 405Q107 405 92 377T68 316T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g></svg></span> denotes the length of edge between these corresponding nodes. </p>
<p>The last line has an integer <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-11-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 645.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></g></svg></span>, denoting the starting position. </p>
<p><strong>Constraints</strong> <br>
<span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-12-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="11.321ex" height="2.343ex" style="vertical-align: -0.505ex;" viewBox="0 -791.3 4874.1 1008.6" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><g transform="translate(778,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(1834,0)"><path stroke-width="1" d="M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z"></path></g><g transform="translate(2816,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(3873,0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z" transform="translate(500,0)"></path></g></g></svg></span> <br>
<span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-13-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="14.073ex" height="2.343ex" style="vertical-align: -0.505ex;" viewBox="0 -791.3 6059.1 1008.6" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><g transform="translate(778,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(1834,0)"><path stroke-width="1" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></g><g transform="translate(3000,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(4057,0)"><path stroke-width="1" d="M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z"></path><path stroke-width="1" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z" transform="translate(500,0)"></path><path stroke-width="1" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z" transform="translate(1001,0)"></path><path stroke-width="1" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z" transform="translate(1501,0)"></path></g></g></svg></span> <br>
<span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-14-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="18.854ex" height="4.176ex" style="vertical-align: -1.171ex;" viewBox="0 -1293.7 8117.8 1798" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><g transform="translate(778,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(1834,0)"><path stroke-width="1" d="M289 629Q289 635 232 637Q208 637 201 638T194 648Q194 649 196 659Q197 662 198 666T199 671T201 676T203 679T207 681T212 683T220 683T232 684Q238 684 262 684T307 683Q386 683 398 683T414 678Q415 674 451 396L487 117L510 154Q534 190 574 254T662 394Q837 673 839 675Q840 676 842 678T846 681L852 683H948Q965 683 988 683T1017 684Q1051 684 1051 673Q1051 668 1048 656T1045 643Q1041 637 1008 637Q968 636 957 634T939 623Q936 618 867 340T797 59Q797 55 798 54T805 50T822 48T855 46H886Q892 37 892 35Q892 19 885 5Q880 0 869 0Q864 0 828 1T736 2Q675 2 644 2T609 1Q592 1 592 11Q592 13 594 25Q598 41 602 43T625 46Q652 46 685 49Q699 52 704 61Q706 65 742 207T813 490T848 631L654 322Q458 10 453 5Q451 4 449 3Q444 0 433 0Q418 0 415 7Q413 11 374 317L335 624L267 354Q200 88 200 79Q206 46 272 46H282Q288 41 289 37T286 19Q282 3 278 1Q274 0 267 0Q265 0 255 0T221 1T157 2Q127 2 95 1T58 0Q43 0 39 2T35 11Q35 13 38 25T43 40Q45 46 65 46Q135 46 154 86Q158 92 223 354T289 629Z"></path></g><g transform="translate(3163,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(3942,0)"><g transform="translate(397,0)"><rect stroke="none" width="3657" height="60" x="0" y="220"></rect><g transform="translate(60,622)"><path stroke-width="1" transform="scale(0.707)" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path><g transform="translate(628,0)"><path stroke-width="1" transform="scale(0.707)" d="M630 29Q630 9 609 9Q604 9 587 25T493 118L389 222L284 117Q178 13 175 11Q171 9 168 9Q160 9 154 15T147 29Q147 36 161 51T255 146L359 250L255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489Q178 487 284 383L389 278L493 382Q570 459 587 475T609 491Q630 491 630 471Q630 464 620 453T522 355L418 250L522 145Q606 61 618 48T630 29Z"></path></g><g transform="translate(1178,0)"><path stroke-width="1" transform="scale(0.707)" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path></g><g transform="translate(1454,0)"><path stroke-width="1" transform="scale(0.707)" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></g><g transform="translate(2082,0)"><path stroke-width="1" transform="scale(0.707)" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path></g><g transform="translate(2632,0)"><path stroke-width="1" transform="scale(0.707)" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></g><g transform="translate(2986,0)"><path stroke-width="1" transform="scale(0.707)" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></g><g transform="translate(3262,0)"><path stroke-width="1" transform="scale(0.707)" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></g></g><g transform="translate(1651,-417)"><path stroke-width="1" transform="scale(0.707)" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path></g></g></g></g></svg></span> <br>
<span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-15-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="15.475ex" height="2.509ex" style="vertical-align: -0.671ex;" viewBox="0 -791.3 6662.9 1080.4" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><g transform="translate(778,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(1834,0)"><path stroke-width="1" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g><g transform="translate(2407,0)"><path stroke-width="1" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path></g><g transform="translate(2852,0)"><path stroke-width="1" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g><g transform="translate(3349,0)"><path stroke-width="1" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path></g><g transform="translate(3794,0)"><path stroke-width="1" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></g><g transform="translate(4718,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(5774,0)"><path stroke-width="1" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></g></g></svg></span> <br>
<span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-16-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="11.787ex" height="2.843ex" style="vertical-align: -0.505ex;" viewBox="0 -1006.6 5075 1223.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><g transform="translate(778,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(1834,0)"><path stroke-width="1" d="M21 287Q22 290 23 295T28 317T38 348T53 381T73 411T99 433T132 442Q161 442 183 430T214 408T225 388Q227 382 228 382T236 389Q284 441 347 441H350Q398 441 422 400Q430 381 430 363Q430 333 417 315T391 292T366 288Q346 288 334 299T322 328Q322 376 378 392Q356 405 342 405Q286 405 239 331Q229 315 224 298T190 165Q156 25 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 114 189T154 366Q154 405 128 405Q107 405 92 377T68 316T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g><g transform="translate(2563,0)"><path stroke-width="1" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path></g><g transform="translate(3620,0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z" transform="translate(500,0)"></path><g transform="translate(1001,393)"><path stroke-width="1" transform="scale(0.707)" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z"></path></g></g></g></svg></span> </p>
<p><strong>If there are edges between the same pair of nodes with different weights, they are to be considered as is, like multiple edges.</strong></p></div></div></div><div class="challenge_output_format"><div class="msB challenge_output_format_title"><p><strong>Output Format</strong></p></div><div class="msB challenge_output_format_body"><div class="hackdown-content"><style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
</style><svg style="display: none;"><defs id="MathJax_SVG_glyphs"></defs></svg><p>For each of the <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-1-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.636ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 704.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z"></path></g></svg></span> test cases, print a single line consisting <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-2-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="6.066ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 2611.9 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path><g transform="translate(1110,0)"><path stroke-width="1" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path></g><g transform="translate(2111,0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></g></g></svg></span> space separated integers denoting the shortest distance of <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-3-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="6.066ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 2611.9 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path><g transform="translate(1110,0)"><path stroke-width="1" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path></g><g transform="translate(2111,0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></g></g></svg></span> nodes other than <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-4-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 645.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></g></svg></span> from starting position <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-5-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 645.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></g></svg></span> in increasing order of their labels. </p>
<p>For unreachable nodes, print <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-6-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="2.971ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 1279 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path><g transform="translate(778,0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></g></g></svg></span>.</p></div></div></div><div class="challenge_sample_input"><div class="msB challenge_sample_input_title"><p><strong>Sample Input</strong></p></div><div class="msB challenge_sample_input_body"><div class="hackdown-content"><style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
</style><svg style="display: none;"><defs id="MathJax_SVG_glyphs"></defs></svg><pre><code>1
4 4
1 2 24
1 4 20
3 1 3
4 3 12
1
</code></pre></div></div></div><div class="challenge_sample_output"><div class="msB challenge_sample_output_title"><p><strong>Sample Output</strong></p></div><div class="msB challenge_sample_output_body"><div class="hackdown-content"><style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
</style><svg style="display: none;"><defs id="MathJax_SVG_glyphs"></defs></svg><pre><code>24 3 15
</code></pre></div></div></div><div class="challenge_explanation"><div class="msB challenge_explanation_title"><p><strong>Explanation</strong></p></div><div class="msB challenge_explanation_body"><div class="hackdown-content"><style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
.MathJax_SVG_LineBox {display: table!important}
.MathJax_SVG_LineBox span {display: table-cell!important; width: 10000em!important; min-width: 0; max-width: none; padding: 0; border: 0; margin: 0}
</style><svg style="display: none;"><defs id="MathJax_SVG_glyphs"></defs></svg><p>The graph given in the test case is shown as :</p>
<p><img src="HackerRank8_files/1485484822-fc27c4a7f4-dijkstra.PNG" alt="image" title=""></p>
<ul>
<li>The straight line is a weighted edge, denoting length of edge between the corresponding nodes.</li>
<li>The nodes S,B,C and D denote the obvious node 1,2,3 and 4 in the test case.</li>
</ul>
<p>The shortest paths followed for the three nodes B,C and D are as follows :</p>
<p><strong>S->B</strong> - Shortest Path Value : <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-1-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="2.325ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 1001 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" d="M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z" transform="translate(500,0)"></path></g></svg></span></p>
<p><strong>S->C</strong> - Shortest Path Value : <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-2-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="1.162ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 500.5 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z"></path></g></svg></span></p>
<p><strong>S->C->D</strong> - Shortest Path Value : <span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-3-Frame"><svg xlink="http://www.w3.org/1999/xlink" width="2.325ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 1001 936.9" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><path stroke-width="1" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z" transform="translate(500,0)"></path></g></svg></span></p></div></div></div></div></div><div data-reactid="173"><aside class="span-sm-4 mlB mjT pull-right fullscreen-hide challenge-sidebar" data-reactid="174"><div class="info" data-reactid="175"><div class="mjB small difficulty-wrapper" data-reactid="176"><div data-reactid="177"><span class="difficulty" data-reactid="178">Hard</span></div><div class="difficulty-divider" data-reactid="179"><span style="display:block;" data-reactid="180"><!-- react-text: 181 -->Submitted <!-- /react-text --><!-- react-text: 182 -->15802<!-- /react-text --><!-- react-text: 183 --> times<!-- /react-text --></span><span style="display:block;" data-reactid="184"><!-- react-text: 185 -->Max Score <!-- /react-text --><strong data-reactid="186">60</strong></span></div></div><p class="mlB" data-reactid="187"><strong data-reactid="188">Need Help?</strong></p><div class="mlB options-border" data-reactid="189"><div class="row psT options-padding-left" data-reactid="190"><div class="span-sm-15 options-padding options-border-bottom" data-reactid="191"><div class="span-sm-3" data-reactid="192"><img src="HackerRank8_files/sidebar_discuss-29ac47c3aeffee3966a1c29b07b60f2e.png" data-reactid="193"></div><div class="span-sm-12" data-reactid="194"><a data-analytics="ChallengeSidebarUI" data-attr1="discussions" data-attr2="dijkstrashortreach" data-attr3="master" href="https://www.hackerrank.com/challenges/dijkstrashortreach/forum" data-reactid="195"><strong data-reactid="196">View Discussions</strong></a></div></div></div><div class="row psT options-padding-left" data-reactid="197"><div class="span-sm-15 options-padding options-border-bottom" data-reactid="198"><div class="span-sm-3" data-reactid="199"><img src="HackerRank8_files/sidebar_discuss-29ac47c3aeffee3966a1c29b07b60f2e.png" data-reactid="200"></div><div class="span-sm-12" data-reactid="201"><a data-analytics="ChallengeSidebarUI" data-attr1="editorial" data-attr2="dijkstrashortreach" data-attr3="master" href="https://www.hackerrank.com/challenges/dijkstrashortreach/editorial" data-reactid="202"><strong data-reactid="203">View Editorial Solution</strong></a></div></div></div><div class="row psT options-padding-left" data-reactid="204"><div class="span-sm-15 options-padding" data-reactid="205"><div class="span-sm-3" data-reactid="206"><img src="HackerRank8_files/sidebar_topscorers-5a8e7857617b4ef1688f82823c7f90a8.png" data-reactid="207"></div><div class="span-sm-12" data-reactid="208"><a data-analytics="ChallengeSidebarUI" data-attr1="topscorers" data-attr2="dijkstrashortreach" data-attr3="master" href="https://www.hackerrank.com/challenges/dijkstrashortreach/leaderboard" data-reactid="209"><strong data-reactid="210">View Top Submissions</strong></a></div></div></div></div><div class="challenge-rating rating" data-reactid="211"><p class="bold zeta rating-label" data-reactid="212">Rate This Challenge: </p><div class="rating" data-reactid="213"><i class="icon cursor icon-star-empty" data-analytics="RatedChallenge" data-attr7="1" data-reactid="214"></i><i class="icon cursor icon-star-empty" data-analytics="RatedChallenge" data-attr7="2" data-reactid="215"></i><i class="icon cursor icon-star-empty" data-analytics="RatedChallenge" data-attr7="3" data-reactid="216"></i><i class="icon cursor icon-star-empty" data-analytics="RatedChallenge" data-attr7="4" data-reactid="217"></i><i class="icon cursor icon-star-empty" data-analytics="RatedChallenge" data-attr7="5" data-reactid="218"></i></div></div><div id="sidebar-more-options" data-reactid="219"><div class="mlB mlT" data-reactid="220"><a target="_blank" id="pdf-link" data-analytics="ChallengeViewSidebarPDF" data-attr1="dijkstrashortreach" href="https://www.hackerrank.com/rest/contests/master/challenges/dijkstrashortreach/download_pdf?language=English" data-reactid="221">Download problem statement</a></div><div class="mlB" data-reactid="222"><a target="_blank" id="test-cases-link" data-analytics="ChallengeViewSidebarTestCases" data-attr1="dijkstrashortreach" href="https://www.hackerrank.com/rest/contests/master/challenges/dijkstrashortreach/download_testcases" data-reactid="223">Download sample test cases</a></div><div class="fullscreen-hide" data-reactid="224"><a class="link" data-analytics="ChallengeViewSuggestEdit" data-attr1="dijkstrashortreach" data-reactid="225"><!-- react-text: 226 -->Suggest Edits<!-- /react-text --></a></div><div class="language-selector pjT" data-reactid="227"><div class="psT hide small color-alt-grey" id="preference-msg" data-reactid="228"><a class="language-preference btn btn-small msB" data-reactid="229">Set as default</a><br data-reactid="230"><p class="mjB" data-reactid="231">You can always change back later.</p></div></div></div><div class="social-share-wrap-2" data-reactid="232"><div class="clearfix" data-reactid="233"><div class="social-share-view-wrap social-buttons mjT pull-left" data-reactid="234"><a class="social-btn cursor facebook-share-btn txt-white" data-reactid="235"><i class="icon-facebook" data-reactid="236"></i></a><a class="social-btn cursor twitter-share-btn txt-white txt-white" data-reactid="237"><i class="icon-twitter" data-reactid="238"></i></a><a class="social-btn cursor linkedin-share-btn txt-white" data-reactid="239"><i class="icon-linkedin" data-reactid="240"></i></a></div></div></div></div></aside></div></div></div></div></div><div class="right-pane split" data-reactid="241"><div class="challenge-request" data-reactid="242"><div class="challenge-input codeeditor-wrapper container fs-container mlB" data-reactid="243"><div data-reactid="244"><div class="codeeditor-view" data-reactid="245"><div id="codeshell-wrapper" data-reactid="246">
<div class="clearfix grey-header fixed-hand0 cap plL plR psT psB" style="position: relative;">
<div class="msT pull-left"><em id="status-text"></em></div>
<div class="fork-dialog cs-dialog hide">
<div class="header">Fork <span class="version-seq"></span>
<i data-analytics="CodeShellForkCode" data-attr1="Cancel" class="icon--single icon-cancel-small close-fork-dialog cursor-pointer pull-right psR"></i>
</div>
<div class="body">
<p class="grey-msg">past buffers are marked read only, you wont be able to edit your current buffer without forking it</p>
<div class="m msT">
<button data-analytics="CodeShellForkCode" data-attr1="ForkCurrentBuffer" class="btn btn-primary fork-version" data-action="fork">Fork <span class="version-seq"></span></button>
<button data-analytics="CodeShellForkCode" data-attr1="CreateNewBuffer" class="btn btn-primary fork-version" data-action="orphan">Create New Buffer</button>
</div>
</div>
</div>
<div class="fork-limit-reached-dialog cs-dialog hide">
<div class="header">Fork Limit Reached</div>
<div class="body">
<p class="grey-msg">You can’t create more than 20 buffers, please delete one of your old bufferes to create a new buffer.</p>
<div class="m msT">
<button class="btn close-fork-limit-reached-dialog">OK</button>
</div>
</div>
</div>
<div class="delete-version-dialog cs-dialog hide">
<div class="header">Delete <span class="version-seq"></span></div>
<div class="body">
<p class="grey-msg">Are you sure you want to delete <strong><span class="version-seq"></span></strong>? This action can’t be undone.</p>
<div class="m msT">
<button class="btn delete-version-button">Yes</button>
</div>
</div>
</div>
<div class="pull-left no-select">
<p style="padding-top: 8px;">
<strong class="version-name">Current Buffer</strong>
<span class="gray-text version-meta">(saved locally, editable)</span>
<a data-analytics="CodeShellShowForkOptions" class="fork-this-version"><i class="icon--grey cursor icon-flow-branch"></i></a>
<a data-analytics="CodeShellShowVersionTimeline" class="show-version-timeline"><i class="icon--grey cursor icon-back-in-time"></i></a>
<a class="delete-active-version hide"><i class="icon--grey cursor icon-trash"></i></a>
</p>
</div>
<div class="pull-right">
<div class="inline large lines inverse pull-right msT msL">
<a class="restorefullscreen force-hide active-link no-select">
<i class="icon-resize-small-alt icon--grey no-select"></i></a>
<a class="fullscreen active-link no-select" data-analytics="Switch to fullscreen"><i class="icon-resize-full-alt icon--grey no-select"></i></a>
<a class="hide" style="display:none;"></a>
<div class="settings-editor" style="position:relative; margin-left: 0px;">
<a class="cursor no-select" data-analytics="CodeShellShowPreferences" id="show-preferences"><i class="icon-cog icon--grey no-select"></i></a>
<div id="pref-pane" style="position: absolute;right: -0.5em;top: 2em;z-index: 9;background: #fff;border: 1px solid #ddd;border-radius: 5px;padding: 10px; width: 20em; display: none;">
<div style="position: absolute;width: 0;right: 0.8em;height: 0;border-left: 7px solid transparent;border-right: 7px solid transparent;border-bottom: 7px solid #ddd;top: -0.4em;"></div>
<div class="formgroup horizontal">
<label class="span5">Editor Mode</label>
<div class="inline">
<div class="btn-group no-select">
<a data-analytics="CodeShellEditorMode" data-attr1="Emacs" class="cursor emacs btn btn-small btn-white editor-mode-button no-select" data-editor="emacs">Emacs</a>
<a data-analytics="CodeShellEditorMode" data-attr1="Normal" class="cursor default btn btn-small btn-white editor-mode-button no-select btn-primary" data-editor="sublime">Normal</a>
<a data-analytics="CodeShellEditorMode" data-attr1="Vim" class="cursor vim btn btn-small btn-white editor-mode-button no-select" data-editor="vim">Vim</a>
</div>
</div>
</div>
<div class="formgroup horizontal">
<label class="span5">Editor Theme</label>
<div class="inline">
<div class="btn-group no-select">
<a data-analytics="CodeShellEditorTheme" data-attr1="Light" class="cursor light btn btn-small btn-white editor-theme-button no-select btn-primary" data-editor="light">Light</a>
<a data-analytics="CodeShellEditorTheme" data-attr1="Dark" class="cursor dark btn btn-small btn-white editor-theme-button no-select" data-editor="dark">Dark</a>
</div>
</div>
</div>
<div class="formgroup horizontal">
<label class="span5">Tab Spaces</label>
<div class="inline">
<div class="btn-group no-select">
<a data-analytics="CodeShellEditorSpace" data-attr1="2" class="cursor 2space btn btn-small btn-white editor-tabspace-button no-select" data-editor="2">2 spaces</a>
<a data-analytics="CodeShellEditorSpace" data-attr1="4" class="cursor 4space btn btn-small btn-white editor-tabspace-button no-select btn-primary" data-editor="4">4 spaces</a>
<a data-analytics="CodeShellEditorSpace" data-attr1="8" class="cursor 8space btn btn-small btn-white editor-tabspace-button no-select" data-editor="8">8 spaces</a>
</div>
</div>
</div>
<div class="formgroup horizontal">
<label class="span5">Intellisense</label>
<div class="inline">
<div class="btn-group no-select">
<a data-analytics="CodeShellAutoComplete" data-attr1="Enable" class="cursor emacs btn btn-small btn-white editor-autocomplete-button no-select btn-primary" data-editor="true">Enable</a>
<a data-analytics="CodeShellAutoComplete" data-attr1="Disable" class="cursor default btn btn-small btn-white editor-autocomplete-button no-select" data-editor="false">Disable</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="pull-right lang-placeholder">
<div class="dummy-lang-container hide"></div>
<div class="select2-container" id="s2id_select-lang"><a href="javascript:void(0)" onclick="return false;" class="select2-choice" tabindex="-1"> <span>C++</span><abbr class="select2-search-choice-close"></abbr> <div><b></b></div></a><input class="select2-focusser select2-offscreen" id="s2id_autogen1" type="text"><div class="select2-drop select2-display-none"> <div class="select2-search select2-search-hidden select2-offscreen"> <input autocomplete="off" autocorrect="off" autocapitilize="off" spellcheck="false" class="select2-input" type="text"> </div> <ul class="select2-results"> </ul></div></div><input id="select-lang" tabindex="-1" class="select2-offscreen" value="cpp" type="hidden">
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="version-timeline">
<div class="version-timeline-inner">
<div class="cross-line"></div>
<div class="start-slab pull-left"></div>
<div class="current-version-ball green-bkg pull-left cursor"></div>
</div>
</div>
<div class="hr_tour-code-solution movable-hand flex-row" style="display: flex;">
<div class="code-checker">
<div id="notification-message" class="clearfix grey-header cap hidden "> </div>
<div class="code-editors" style="max-height: 1033px;">
<div class="loading-mode" style="display: none;">Loading Editor... </div>
<div class="code-body" style="display: block;">
<textarea id="codeview" style="width: 100%; display: none;"></textarea><div class="CodeMirror cm-s-default CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 5px; left: 44px;"><textarea style="position: absolute; bottom: -1em; padding: 0px; width: 1px; height: 1em; outline: medium none currentcolor;" autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" wrap="off"></textarea></div><div class="CodeMirror-vscrollbar" cm-not-content="true" style="bottom: 0px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-hscrollbar" cm-not-content="true"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1" draggable="true"><div class="CodeMirror-sizer" style="margin-left: 39px; margin-bottom: -17px; border-right-width: 13px; min-height: 921px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div style="position: relative; outline: medium none currentcolor;" role="presentation"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>45</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-cursors"><div class="CodeMirror-cursor" style="left: 4px; top: 0px; height: 20.2833px;"> </div></div><div class="CodeMirror-code" role="presentation" style=""><div style="position: relative;" class="CodeMirror-activeline"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -39px; width: 39px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">1</div><div class="CodeMirror-gutter-elt" style="left: 29px; width: 9px;"><div class="CodeMirror-foldgutter-open CodeMirror-guttermarker-subtle"></div></div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <map></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <set></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <list></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <cmath></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <ctime></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <deque></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <queue></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <stack></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <string></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <bitset></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <cstdio></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <limits></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <vector></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <climits></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <cstring></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <cstdlib></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <fstream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <numeric></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <sstream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <algorithm></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-meta">#include <unordered_map></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span cm-text=""></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">25</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span cm-text=""></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">26</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span cm-text=""></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">27</div><div class="CodeMirror-gutter-elt" style="left: 29px; width: 9px;"><div class="CodeMirror-foldgutter-open CodeMirror-guttermarker-subtle"></div></div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-type">int</span> <span class="cm-def">main</span>(){</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">28</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-type">int</span> <span class="cm-variable">t</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">29</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-variable">cin</span> <span class="cm-operator">>></span> <span class="cm-variable">t</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">30</div><div class="CodeMirror-gutter-elt" style="left: 29px; width: 9px;"><div class="CodeMirror-foldgutter-open CodeMirror-guttermarker-subtle"></div></div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-keyword">for</span>(<span class="cm-type">int</span> <span class="cm-variable">a0</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">a0</span> <span class="cm-operator"><</span> <span class="cm-variable">t</span>; <span class="cm-variable">a0</span><span class="cm-operator">++</span>){</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">31</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-type">int</span> <span class="cm-variable">n</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">32</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-type">int</span> <span class="cm-variable">m</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">33</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-variable">cin</span> <span class="cm-operator">>></span> <span class="cm-variable">n</span> <span class="cm-operator">>></span> <span class="cm-variable">m</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">34</div><div class="CodeMirror-gutter-elt" style="left: 29px; width: 9px;"><div class="CodeMirror-foldgutter-open CodeMirror-guttermarker-subtle"></div></div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-keyword">for</span>(<span class="cm-type">int</span> <span class="cm-variable">a1</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">a1</span> <span class="cm-operator"><</span> <span class="cm-variable">m</span>; <span class="cm-variable">a1</span><span class="cm-operator">++</span>){</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">35</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-type">int</span> <span class="cm-variable">x</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">36</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-type">int</span> <span class="cm-variable">y</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">37</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-type">int</span> <span class="cm-variable">r</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">38</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-variable">cin</span> <span class="cm-operator">>></span> <span class="cm-variable">x</span> <span class="cm-operator">>></span> <span class="cm-variable">y</span> <span class="cm-operator">>></span> <span class="cm-variable">r</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">39</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">40</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-type">int</span> <span class="cm-variable">s</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">41</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-variable">cin</span> <span class="cm-operator">>></span> <span class="cm-variable">s</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">42</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">43</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">44</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -39px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">45</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span cm-text=""></span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 13px; width: 1px; border-bottom: 0px solid transparent; top: 921px;"></div><div class="CodeMirror-gutters" style="height: 934px; left: 0px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 29px;"></div><div class="CodeMirror-gutter CodeMirror-foldgutter"></div></div></div></div>
</div>
<div class="clearfix"></div>
</div>
<div id="codeeditor-statusbar" class="clearfix psA codeeditor_statusbar">
<span id="statusbar-mode"></span>
<div class="pull-right">
<span id="statusbar-line">Line: 1</span>
<span id="statusbar-col">Col: 1</span>
<span id="statusbar-count"></span>
</div>
</div>
</div>
</div><div class="clearfix pmR pmL pmB plT fixed-hand1 codeshell-footer">
<div class="pull-right">
<button class="btn bb-compile msR " data-analytics="Compile and Test">Run Code</button>
<button class="btn btn-primary bb-submit ans-submit" data-analytics="Submit Code">Submit Code</button>
</div>
<div class="pull-left inline">
<button class="btn btn-text upload_file mlR" data-analytics="Upload File" type="button"><i class="icon-upload"></i>Upload Code as File</button>
<div class="mmT">
<label for="customtestcase"><div class="custom-checkbox-v3"><input id="customtestcase" type="checkbox"><span></span></div><span class="lmT msL">Test against custom input</span></label>
<textarea rows="5" id="custominput" style="display:none"></textarea>
</div>
</div>
</div></div><div id="submission-message" data-reactid="249"></div><!-- react-empty: 250 --><!-- react-empty: 251 --><!-- react-empty: 252 --><div class="__react_component_tooltip place-top type-dark " data-id="tooltip" data-reactid="253"></div></div></div></div></div><div class="challenge-response container fs-container" data-reactid="254"></div></div></div></div></div></section></div><footer class="page_footer community-footer" data-reactid="255"><div data-reactid="256"><div class="text-center" data-reactid="257"><p style="font-size:14px;margin-top:5px;margin-bottom:0px;" data-reactid="258"><span class="internal-links" data-reactid="259"><a target="_blank" href="https://www.hackerrank.com/calendar" class="footer-link calendar" data-analytics="FooterLinkCalendar" data-reactid="260">Contest Calendar</a><span class="divider" data-reactid="261">|</span><a target="_blank" href="https://blog.hackerrank.com/" class="footer-link blog" data-analytics="FooterLinkBlog" data-reactid="262">Blog</a><span class="divider" data-reactid="263">|</span><a target="_blank" href="https://www.hackerrank.com/scoring" class="footer-link scoring" data-analytics="FooterLinkScoring" data-reactid="264">Scoring</a><span class="divider" data-reactid="265">|</span><a target="_blank" href="https://www.hackerrank.com/environment" class="footer-link environment" data-analytics="FooterLinkEnvironment" data-reactid="266">Environment</a><span class="divider" data-reactid="267">|</span><a target="_blank" href="https://www.hackerrank.com/faq" class="footer-link faq" data-analytics="FooterLinkFAQ" data-reactid="268">FAQ</a><span class="divider" data-reactid="269">|</span></span><a target="_blank" href="https://www.hackerrank.com/aboutus" class="footer-link" data-analytics="FooterLinkAboutUs" data-reactid="270">About Us</a><span class="divider" data-reactid="271">|</span><a target="_blank" href="https://help.hackerrank.com/hc/en-us" class="footer-link" data-analytics="FooterLinkSupport" data-reactid="272">Support</a><span class="divider" data-reactid="273">|</span><a target="_blank" href="https://www.hackerrank.com/careers" class="footer-link" data-analytics="FooterLinkCareers" data-reactid="274">Careers</a><span class="divider" data-reactid="275">|</span><a target="_blank" href="https://www.hackerrank.com/terms-of-service" class="footer-link" data-analytics="FooterLinkTermsOfService" data-reactid="276">Terms Of Service</a><span class="divider" data-reactid="277">|</span><a target="_blank" href="https://www.hackerrank.com/privacy" class="footer-link" data-analytics="FooterLinkPrivacyPolicy" data-reactid="278">Privacy Policy</a><span class="divider" data-reactid="279">|</span><a href="https://www.hackerrank.com/support/feature" target="_blank" class="footer-link featureRequestButton" data-analytics="FooterLinkFeatureRequest" data-reactid="280">Request a Feature</a></p></div></div></footer><!-- react-empty: 281 --></div></div></div></div><!--Required to handle event bubbling of click in ios safari -->
<!-- Vendor scripts -->
<script>
/*** webpack menifest data ***/
var webpackChunkManifest = {"0":"hackerrank_r_community-e8b13deda13c9533154b.js","1":"hackerrank_r_work-5fdf8ed77cbcdc460d6b.js","2":"hackerrank_r_uikit-f5443c4043f2d7ba278b.js","3":"hackerrank_r_app-c82782ffcb1c5c932a5f.js","4":"hackerrank_r_hackerlevel-88d861a9f45caedd4a8b.js","5":"hackerrank_r_code_snippets-c279e3b2cac4c07804ee.js","6":"hackerrank_r_challenge_list_v2-f72a64e383fc56d166e1.js","7":"hackerrank_r_jobs-db6c0132fa3e038d764c.js","8":"hackerrank_r_testinvite-24a81c421c0d56e7f539.js","9":"hackerrank_r_onboarding-27802227e5ac1c221c4d.js","10":"hackerrank_r_library-90772cd9c077b864c901.js","11":"hackerrank_r_charts-2fbe0ccfcd65c2a0e883.js","12":"hackerrank_r_calendar-c94786944cd226558f42.js","13":"hackerrank_r_testquestions-2de7fc46d303a0cd4d1a.js","14":"hackerrank_r_testsettings-d7d52168ead9c7e91d28.js","15":"hackerrank_r_testinsights-633034280a7d21b0c12d.js","16":"hackerrank_r_challenge-62369df05b7279036344.js","17":"hackerrank_r_dashboard-bfe6a789d3d24c1d4a76.js","18":"hackerrank_r_profile-f5f10e6820aa1bc20764.js","19":"hackerrank_r_singletest-11fb3d0c508c57435a37.js","20":"hackerrank_r_testreportslisting-c6fbaf05bfef3532121e.js","21":"hackerrank_r_leaderboard-9d9dcaa7033cf35f29c8.js","22":"hackerrank_r_challenge_list-62802914fb34b5fe267d.js","23":"hackerrank_r_dashboardv2-82b16a83230f3ec9069e.js","24":"hackerrank_r_rank-c263ff63bd2b62c01248.js","25":"hackerrank_r_contest-ec25cda400bb8f0d9664.js","26":"hackerrank_r_codeshell_lib-e6962ca44c2864fa175e.js"};
var webpackManifest = {"codeshell_editor_theme_m.css":"codeshell_editor_theme_m-6076207a05.css","hackerrank_r_app.css":"hackerrank_r_app-ebafff4fbe.css","hackerrank_r_community.css":"hackerrank_r_community-b949defbb1.css","hackerrank_r_old_trimmed.css":"hackerrank_r_old_trimmed-3801841774.css","hackerrank_r_uikit.css":"hackerrank_r_uikit-803c6ea899.css","hackerrank_r_work.css":"hackerrank_r_work-f9e5aaeb93.css","hackerrank_r_app.js":"hackerrank_r_app-c82782ffcb1c5c932a5f.js","hackerrank_r_calendar.js":"hackerrank_r_calendar-c94786944cd226558f42.js","hackerrank_r_challenge.js":"hackerrank_r_challenge-62369df05b7279036344.js","hackerrank_r_challenge_list.js":"hackerrank_r_challenge_list-62802914fb34b5fe267d.js","hackerrank_r_challenge_list_v2.js":"hackerrank_r_challenge_list_v2-f72a64e383fc56d166e1.js","hackerrank_r_charts.js":"hackerrank_r_charts-2fbe0ccfcd65c2a0e883.js","hackerrank_r_code_snippets.js":"hackerrank_r_code_snippets-c279e3b2cac4c07804ee.js","hackerrank_r_codeshell_lib.js":"hackerrank_r_codeshell_lib-e6962ca44c2864fa175e.js","hackerrank_r_common.js":"hackerrank_r_common-27f87a97d6303aeff8c0.js","hackerrank_r_community.js":"hackerrank_r_community-e8b13deda13c9533154b.js","hackerrank_r_contest.js":"hackerrank_r_contest-ec25cda400bb8f0d9664.js","hackerrank_r_dashboard.js":"hackerrank_r_dashboard-bfe6a789d3d24c1d4a76.js","hackerrank_r_dashboardv2.js":"hackerrank_r_dashboardv2-82b16a83230f3ec9069e.js","hackerrank_r_hackerlevel.js":"hackerrank_r_hackerlevel-88d861a9f45caedd4a8b.js","hackerrank_r_jobs.js":"hackerrank_r_jobs-db6c0132fa3e038d764c.js","hackerrank_r_leaderboard.js":"hackerrank_r_leaderboard-9d9dcaa7033cf35f29c8.js","hackerrank_r_library.js":"hackerrank_r_library-90772cd9c077b864c901.js","hackerrank_r_onboarding.js":"hackerrank_r_onboarding-27802227e5ac1c221c4d.js","hackerrank_r_profile.js":"hackerrank_r_profile-f5f10e6820aa1bc20764.js","hackerrank_r_rank.js":"hackerrank_r_rank-c263ff63bd2b62c01248.js","hackerrank_r_singletest.js":"hackerrank_r_singletest-11fb3d0c508c57435a37.js","hackerrank_r_testinsights.js":"hackerrank_r_testinsights-633034280a7d21b0c12d.js","hackerrank_r_testinvite.js":"hackerrank_r_testinvite-24a81c421c0d56e7f539.js","hackerrank_r_testquestions.js":"hackerrank_r_testquestions-2de7fc46d303a0cd4d1a.js","hackerrank_r_testreportslisting.js":"hackerrank_r_testreportslisting-c6fbaf05bfef3532121e.js","hackerrank_r_testsettings.js":"hackerrank_r_testsettings-d7d52168ead9c7e91d28.js","hackerrank_r_uikit.js":"hackerrank_r_uikit-f5443c4043f2d7ba278b.js","hackerrank_r_work.js":"hackerrank_r_work-5fdf8ed77cbcdc460d6b.js","hackerrank_r_vendor.js":"hackerrank_r_vendor-4966df136c.js"};
</script>
<script>
//HR namespace
var HR = {};
HR.development = false;
HR.assetPath = 'https://hrcdn.net/hackerrank/assets/';
HR.pageLoadTime = Date.now();
HR.productNamespace = 'hackerrank';
HR.production = true;
HR.devServer = false;
HR.isIsomorphic = true;
HR.pusher = '{"key":"a280047e3b323ccb1b65","cluster":"mt1"}';
</script>
<!-- Vendor scripts -->
<script src="HackerRank8_files/hackerrank_r_vendor-4966df136c.js"></script>
<script src="HackerRank8_files/hackerrank_r_common-27f87a97d6303aeff8c0.js"></script>
<script src="HackerRank8_files/hackerrank_r_app-c82782ffcb1c5c932a5f.js"></script>
<script>
var getUser = (function() {
var userData;
try{
if (typeof userData === 'undefined') {
userData = JSON.parse(decodeURI($('#initialUserData').html()));
$('#initialUserData').remove();
}
} catch(e){
console.log('No initial User data found');
}
return function() {
return userData;
}
})();
</script>
<!-- setting up sentry -->
<script src="HackerRank8_files/raven.js" async="" crossorigin="anonymous" id="raven"></script>
<script>
(function(window, queue, loaded, script, productNamespace, user) {
window.onerror = function e(message, file, lineNo, columnNo, error) {
if (loaded) return;
queue.push([message, file, lineNo, columnNo, error]);
};
window.onunhandledrejection = function e(error) {
if (loaded) return;
queue.push([
error.reason.reason || error.reason.message,
error.type,
JSON.stringify(error.reason),
]);
};
script.onreadystatechange = script.onload = function() {
if (loaded) return;
loaded = true;
Raven.config('https://[email protected]/234162', {
release: "1c9503a645a9f26f41569c3bb4b88b817e0c4b27"
}).install();
var setupRaven = function(user) {
var userContext = {};
if (productNamespace === 'hackerrank' && !!user.username) {
userContext.handle = user.username;
} else if (productNamespace === 'hackerrankx' && !!user.email) {
userContext.handle = user.email;
}
Raven.setUserContext(userContext);
Raven.setExtraContext({
cdnUrl: Cookies.get("cdn_url")
});
}
setupRaven(user);
$(window).on('initializeTracking', function(e, user) {
setupRaven(user);
});
window.onunhandledrejection = function e(error) {
Raven.captureException(new Error(error.reason.reason || error.reason.message), {
extra: {
type: error.type,
reason: JSON.stringify(error.reason),
},
});
};
queue.forEach(function(error) {
Raven.captureException(error[4] || new Error(error[0]), {
extra: {
file: error[1],
line: error[2],
col: error[3],
},
});
});
};
}(window, [], false, document.getElementById('raven'), HR.productNamespace, getUser()));
</script>
<!-- google analytics tracking -->
<script>
var _gaq = _gaq || [];
_gaq.push(['candidate_company._setAccount', 'UA-45092266-1']);
_gaq.push(['candidate_company._trackPageview']);
_gaq.push(['_setCampSourceKey', 'utm_source']);
_gaq.push(['_setCampMediumKey', 'utm_medium']);
_gaq.push(['_setCampContentKey', 'utm_keyword']);
_gaq.push(['_setCampTermKey', 'utm_keyword']);
_gaq.push(['_setCampNameKey', 'utm_campaign']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- Pending candidate site custom GA code -->
<!-- google analytics tracking end-->
<!-- mixpanel tracking -->
<script type="text/javascript">
(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init("bcb75af88bccc92724ac5fd79271e1ff");
mixpanel.init("86cf4681911d3ff600208fdc823c5ff5", {}, "jobs_test");
mixpanel.identify(Cookies.get("hackerrank_mixpanel_token"));
</script>
<!-- mixpanel tracking end-->
<!-- auryc tracking start -->
<script type="text/javascript">
function aurycProps(user) {
if(HR.productNamespace === 'hackerrankx') {
userProps = {
email: user.email,
firstname: user.firstname,
lastname: user.lastname,
user_id: user.id,
user_role: user.role,
company: user.company.name,
company_id: user.company.id,
plan_name: user.company.plan_name
}
} else if(HR.productNamespace === 'hackerrank') {
userProps = {
email: user.email,
username: user.username,
user_id: user.id
}
}
return userProps;
}
setupAuryc = function(user) {
hackerrankAurycSrc = "//cdn.userty.com/207-hackerrankcom/container.js";
hackerrankxAurycSrc = "//cdn.userty.com/235-hackerrankcomcommunity/container.js";
if(HR.productNamespace === 'hackerrankx') {
if (!(user && user.company && [25227, 4357, 70014].indexOf(user.company_id) > -1)) return;
src = hackerrankAurycSrc;
} else if(HR.productNamespace === 'hackerrank') {
if (!(user && user.username)) return;
src = hackerrankxAurycSrc;
}
;(function (g) { g.aurycReadyCb = g.aurycReadyCb || []; var d = document, i, am = d.createElement("script"), h = d.head || d.getElementsByTagName("head")[0],aex = { "src": src, "data-cfasync": "false", "async": "true", "defer": "true", "data-vendor": "userty", "data-role": "container", "charset": "utf-8" }; for (var attr in aex) { am.setAttribute(attr,aex[attr]); } h.appendChild(am); })(window);
userProps = aurycProps(user);
if (window.auryc) {
window.auryc.identify(user.email);
window.auryc.addUserProperties(userProps);
} else if (window.aurycReadyCb) {
window.aurycReadyCb.push(function() {
window.auryc.identify(user.email);
window.auryc.addUserProperties(userProps);
});
}
}
setupAuryc(getUser());
$(window).on('initializeTracking', function(e, user) {
setupAuryc(user);
});
</script>
<!-- auryc tracking end -->
<!-- HeapAnalytics tracking start -->
<script type="text/javascript">
var heap = [];
var attrs = ["clearEventProperties","identify","setEventProperties","track","unsetEventProperty"];
for (var attribute in attrs) {
heap[attrs[attribute]] = function () {};
}
</script>
<!-- HeapAnalytics tracking end -->
<!-- Marketo to be added later -->
<!-- Olark start -->
<!-- Olark end -->
<!-- Bizible -->
<!-- HR metrics init -->
<script type="text/javascript">
(function() {
hr_metrics.init({
product: 'hackerrank',
use_cookie: true,
uid_cookie_key: 'hackerrank_mixpanel_token',
uid_token_cookie_key: 'metrics_user_identifier',
session_cookie_key: 'session_id',
metrics_endpoint: 'https://metrics.hackerrank.com/metrics'
});
})();
</script>
<!-- hrutm_params -->