Task: | Detour |
Sender: | Antti Röyskö |
Submission time: | 2017-10-24 18:37:50 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.03 s | details |
#2 | ACCEPTED | 0.04 s | details |
#3 | ACCEPTED | 0.04 s | details |
#4 | ACCEPTED | 0.06 s | details |
#5 | ACCEPTED | 0.05 s | details |
#6 | ACCEPTED | 0.04 s | details |
#7 | ACCEPTED | 0.05 s | details |
#8 | ACCEPTED | 0.06 s | details |
#9 | ACCEPTED | 0.06 s | details |
#10 | ACCEPTED | 0.04 s | details |
#11 | ACCEPTED | 0.03 s | details |
#12 | ACCEPTED | 0.14 s | details |
#13 | ACCEPTED | 0.03 s | details |
#14 | ACCEPTED | 0.04 s | details |
#15 | ACCEPTED | 0.04 s | details |
#16 | ACCEPTED | 0.20 s | details |
#17 | ACCEPTED | 0.22 s | details |
#18 | ACCEPTED | 0.05 s | details |
#19 | ACCEPTED | 0.04 s | details |
#20 | ACCEPTED | 0.04 s | details |
#21 | ACCEPTED | 0.03 s | details |
#22 | ACCEPTED | 0.05 s | details |
#23 | ACCEPTED | 0.04 s | details |
#24 | ACCEPTED | 0.04 s | details |
#25 | ACCEPTED | 0.04 s | details |
#26 | ACCEPTED | 0.04 s | details |
#27 | ACCEPTED | 0.03 s | details |
#28 | ACCEPTED | 0.03 s | details |
#29 | ACCEPTED | 0.04 s | details |
#30 | ACCEPTED | 0.05 s | details |
#31 | ACCEPTED | 0.05 s | details |
#32 | ACCEPTED | 0.07 s | details |
#33 | ACCEPTED | 0.07 s | details |
#34 | ACCEPTED | 0.09 s | details |
#35 | ACCEPTED | 0.07 s | details |
#36 | ACCEPTED | 0.08 s | details |
Compiler report
input/code.cpp: In function 'void gg(int)': input/code.cpp:21:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i=0; i<rt[c].size(); ++i){ ^ input/code.cpp:28:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i=0; i<rt[c].size(); ++i){ ^ input/code.cpp: In function 'int main()': input/code.cpp:55:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i=0; i<rt[c].size(); ++i) { ^
Code
#include <iostream> #include <vector> #include <queue> #define F first #define S second #define MP make_pair using namespace std; int n, m; vector<pair<int, int> > rt[101010]; bool u[101010]; long long d1[101010]; int e[101010]; void gg(int c){ long long md=1222333444555666777ll; int mi=0; for (int i=0; i<rt[c].size(); ++i){ int w=rt[c][i].F; if (d1[w]+rt[c][i].S<md){ md=d1[w]+rt[c][i].S; mi=i; } } for (int i=0; i<rt[c].size(); ++i){ if (i==mi) continue; int w=rt[c][i].F; if (u[w]) continue; u[w]=1; e[w]=c; gg(w); } } int main(){ cin >> n >> m; for (int i=0; i<m; ++i){ int a, b, d; cin >> a >> b >> d; rt[a].push_back(MP(b, d)); rt[b].push_back(MP(a, d)); } priority_queue<pair<long long, int> > p; p.push(MP(0, 1)); while (p.size()){ long long d=-p.top().F; int c=p.top().S; p.pop(); if (u[c]) continue; u[c]=1; d1[c]=d; for (int i=0; i<rt[c].size(); ++i) { int w=rt[c][i].F; long long dd=d+rt[c][i].S; if (u[w]) continue; p.push(MP(-dd, w)); } } for (int i=0; i<n; ++i) u[i]=0; for (int i=0; i<n; ++i) e[i]=-1; u[0]=1; gg(0); if (e[1]==-1){ cout << "impossible\n"; }else{ vector<int> ans; int c=1; while (c){ ans.push_back(c); c=e[c]; } ans.push_back(0); cout << ans.size() << " "; for (int i=ans.size()-1; i>=0; --i) cout << ans[i] << " "; cout << "\n"; } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
12 12 6 3 81 1 0 100 0 7 90 1 8 110 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 2
Verdict: ACCEPTED
input |
---|
45 990 0 1 37770 0 2 202571 0 3 7492 0 4 22678 ... |
correct output |
---|
5 0 36 17 34 1 |
user output |
---|
2 0 1 |
Test 3
Verdict: ACCEPTED
input |
---|
45 990 0 1 247530 0 2 417002 0 3 352223 0 4 342984 ... |
correct output |
---|
3 0 11 1 |
user output |
---|
2 0 1 |
Test 4
Verdict: ACCEPTED
input |
---|
484 924 459 478 90469 372 441 103116 25 396 123727 416 115 167580 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 5
Verdict: ACCEPTED
input |
---|
1000 1000 181 16 402132 585 137 419860 463 188 484066 933 709 493402 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 6
Verdict: ACCEPTED
input |
---|
1000 5000 308 824 971 843 327 594 246 424 593 931 755 566 ... |
correct output |
---|
8 0 836 157 470 591 405 294 1 |
user output |
---|
695 0 293 764 812 376 912 357 ... |
Test 7
Verdict: ACCEPTED
input |
---|
1000 5000 222 785 459 786 572 87 824 990 1220 152 284 1138 ... |
correct output |
---|
6 0 98 658 162 669 1 |
user output |
---|
818 0 911 613 441 48 26 654 59... |
Test 8
Verdict: ACCEPTED
input |
---|
1000 20000 121 738 3832 235 903 3796 771 433 1967 960 260 4454 ... |
correct output |
---|
3 0 193 1 |
user output |
---|
902 0 59 943 516 130 112 346 3... |
Test 9
Verdict: ACCEPTED
input |
---|
1000 20000 515 416 1284 142 303 3021 561 705 1212 662 963 4088 ... |
correct output |
---|
7 0 931 506 812 978 279 1 |
user output |
---|
561 0 371 204 608 875 466 956 ... |
Test 10
Verdict: ACCEPTED
input |
---|
1000 1156 97 275 286 607 425 54 30 152 347 231 67 337 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 11
Verdict: ACCEPTED
input |
---|
1000 2015 620 884 256 238 223 400 138 620 165 189 668 70 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 12
Verdict: ACCEPTED
input |
---|
50001 75001 0 2 1 2 3 1 3 4 1 4 5 1 ... |
correct output |
---|
25000 0 4 6 8 10 12 14 16 18 2... |
user output |
---|
25000 0 4 6 8 10 12 14 16 18 2... |
Test 13
Verdict: ACCEPTED
input |
---|
1001 1501 0 2 1 2 3 1 3 4 1 4 5 1 ... |
correct output |
---|
500 0 4 6 8 10 12 14 16 18 20 ... |
user output |
---|
500 0 4 6 8 10 12 14 16 18 20 ... |
Test 14
Verdict: ACCEPTED
input |
---|
2001 2005 0 3 3 3 4 1 4 5 3 5 6 3 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 15
Verdict: ACCEPTED
input |
---|
2001 2007 0 2 1 2 3 1 3 4 1 4 5 1 ... |
correct output |
---|
218 0 10 9 8 7 6 100 99 400 39... |
user output |
---|
218 0 10 9 8 7 6 100 99 400 39... |
Test 16
Verdict: ACCEPTED
input |
---|
10000 100000 8865 5390 8390 3911 3120 16356 2155 8860 5312 1660 2808 15360 ... |
correct output |
---|
9 0 6336 6942 3767 5249 6076 7... |
user output |
---|
5030 0 1571 5856 8978 9594 181... |
Test 17
Verdict: ACCEPTED
input |
---|
20000 99992 5068 10219 683 13643 5445 15656 10464 14025 12163 18066 2410 379 ... |
correct output |
---|
10 0 12600 16920 11197 2863 10... |
user output |
---|
16354 0 12600 6044 5513 16722 ... |
Test 18
Verdict: ACCEPTED
input |
---|
50 200 19 13 90 7 38 84 37 9 71 42 18 17 ... |
correct output |
---|
3 0 41 1 |
user output |
---|
22 0 19 13 4 28 36 23 27 20 12... |
Test 19
Verdict: ACCEPTED
input |
---|
50 200 16 26 17 18 45 56 24 47 20 27 2 98 ... |
correct output |
---|
7 0 4 3 21 36 46 1 |
user output |
---|
33 0 25 29 10 9 18 45 11 8 3 2... |
Test 20
Verdict: ACCEPTED
input |
---|
50 500 5 38 125 38 4 15 3 19 74 28 30 70 ... |
correct output |
---|
3 0 46 1 |
user output |
---|
30 0 45 24 25 30 28 39 3 19 27... |
Test 21
Verdict: ACCEPTED
input |
---|
50 750 25 42 122 43 29 37 40 42 50 5 10 37 ... |
correct output |
---|
3 0 24 1 |
user output |
---|
27 0 12 47 6 35 39 20 8 41 3 4... |
Test 22
Verdict: ACCEPTED
input |
---|
50 100 30 1 15 31 7 9 13 20 2 43 41 16 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 23
Verdict: ACCEPTED
input |
---|
2 1 0 1 1 |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 24
Verdict: ACCEPTED
input |
---|
5 6 0 2 10 2 1 10 2 3 5 3 1 10 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 25
Verdict: ACCEPTED
input |
---|
6 8 0 5 5 1 5 5 0 2 10 2 1 10 ... |
correct output |
---|
5 0 2 3 4 1 |
user output |
---|
5 0 2 3 4 1 |
Test 26
Verdict: ACCEPTED
input |
---|
10 11 4 2 6 8 0 7 5 3 9 5 9 5 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 27
Verdict: ACCEPTED
input |
---|
10 20 0 3 5 0 7 2 1 8 7 4 9 8 ... |
correct output |
---|
4 0 9 8 1 |
user output |
---|
5 0 3 9 8 1 |
Test 28
Verdict: ACCEPTED
input |
---|
10 20 1 9 5 5 8 8 4 5 4 7 9 7 ... |
correct output |
---|
3 0 7 1 |
user output |
---|
3 0 7 1 |
Test 29
Verdict: ACCEPTED
input |
---|
10 45 4 7 9 6 0 1 4 5 3 3 9 4 ... |
correct output |
---|
2 0 1 |
user output |
---|
7 0 3 9 7 4 5 1 |
Test 30
Verdict: ACCEPTED
input |
---|
10 45 8 7 2 5 6 17 2 0 11 7 9 7 ... |
correct output |
---|
3 0 8 1 |
user output |
---|
6 0 2 9 7 8 1 |
Test 31
Verdict: ACCEPTED
input |
---|
4 5 0 2 2 2 3 2 3 1 2 3 0 5 ... |
correct output |
---|
4 0 3 2 1 |
user output |
---|
4 0 3 2 1 |
Test 32
Verdict: ACCEPTED
input |
---|
5000 20004 4934 3850 3901 4737 4183 9932 2434 4806 8895 2254 3238 9739 ... |
correct output |
---|
10 0 472 2245 1984 22 1349 186... |
user output |
---|
2416 0 914 1673 4416 4378 2595... |
Test 33
Verdict: ACCEPTED
input |
---|
5000 20002 722 3243 6823 2087 2234 6716 895 4028 3850 2235 2837 1751 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 34
Verdict: ACCEPTED
input |
---|
5000 20001 3790 2581 6986 2675 2646 673 4762 4055 284 679 3234 5098 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 35
Verdict: ACCEPTED
input |
---|
10000 20207 7918 5203 2577 8427 684 280 6378 5210 2723 5990 5019 2482 ... |
correct output |
---|
impossible |
user output |
---|
impossible |
Test 36
Verdict: ACCEPTED
input |
---|
10000 20205 1789 3919 6918 9162 9077 2792 2649 796 2018 6481 9465 2188 ... |
correct output |
---|
impossible |
user output |
---|
impossible |