QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#218558#2879. Kaleidoscopic RouteSnigetWA 127ms15656kbC++232.3kb2023-10-18 15:06:592023-10-18 15:06:59

Judging History

你现在查看的是最新测评结果

  • [2023-10-18 15:06:59]
  • 评测
  • 测评结果:WA
  • 用时:127ms
  • 内存:15656kb
  • [2023-10-18 15:06:59]
  • 提交

answer

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

struct sol {
    long long dist = INT64_MAX, mn = INT64_MAX, mx = -1;
    
};


long long n;
vector<vector<pair<long long, long long> > > adj;

vector<long long> bfs(long long s,long long t) {
    // длина любого кратчайшего пути не превосходит n - 1,
    // поэтому n - достаточное значение для "бесконечности";
    // после работы алгоритма dist[v] = n, если v недостижима из s
    vector<sol> dist(n+1);
    vector<long long> p(n+1, -1);
    dist[s].dist = 0;
    queue<long long> q;
    q.push(s);

    while (!q.empty()) {
        long long v = q.front();
        q.pop();
        for (pair<long long, long long> u : adj[v]) {
            if (dist[u.first].dist > dist[v].dist + 1) {
                p[u.first] = v;
                dist[u.first].dist = dist[v].dist + 1;
                dist[u.first].mn = min(dist[v].mn, u.second);
                dist[u.first].mx = max(dist[v].mx, u.second);
                q.push(u.first);
            }
            else if (dist[u.first].dist == dist[v].dist + 1) {
                if (abs(dist[u.first].mx - dist[u.first].mn) < abs(max(dist[v].mx, u.second) - min(dist[v].mn, u.second))) {
                    p[u.first] = v;
                    dist[u.first].dist = dist[v].dist + 1;
                    dist[u.first].mn = min(dist[v].mn, u.second);
                    dist[u.first].mx = max(dist[v].mx, u.second);
                    q.push(u.first);
                }
            }
        }
    }

    vector<long long> path;
    while (t != -1) {
        path.push_back(t);
        t = p[t];
    }
    return path;
}

int main()
{
    long long m;
    cin >> n >> m;
    adj.resize(n + 1);
    long long a, b, c;
    for (long long i = 0; i < m; i++) {
        cin >> a >> b >> c;
        adj[a].push_back({ b,c });
        adj[b].push_back({ a,c });
    }
    vector<long long> otv = bfs(1, n);
    cout << otv.size() - 1 << '\n';
    for (long long i = otv.size() - 1; i >= 0; i--) {
        cout << otv[i] << ' ';
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

input:

6 8
1 5 2
5 2 5
3 5 4
1 3 10
3 4 6
4 5 7
4 6 8
2 6 1

output:

3
1 5 4 6 

result:

ok 3 6

Test #2:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

10 20
1 9 34
6 3 80
7 3 15
5 4 73
4 1 42
8 6 92
2 10 25
4 3 8
9 3 79
3 1 11
9 2 74
10 1 83
3 2 6
10 3 38
10 4 48
1 5 38
6 2 43
4 2 55
8 7 90
3 5 4

output:

1
1 10 

result:

ok 1 0

Test #3:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

24 65
22 11 519
2 4 585
8 17 647
1 11 464
13 4 596
12 10 733
24 21 106
1 14 345
23 5 430
2 3 137
16 7 891
16 4 807
14 3 465
4 22 532
16 9 346
21 8 859
18 15 631
9 5 914
19 17 729
1 2 546
5 15 43
2 12 349
19 9 642
13 3 441
20 15 359
21 11 645
9 14 992
4 23 9
23 9 34
24 16 117
16 18 349
10 22 285
22 5...

output:

2
1 11 24 

result:

ok 2 208

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

53 123
43 38 999
7 24 718
6 33 393
16 15 734
21 39 604
27 15 828
45 31 747
23 4 538
14 41 224
38 9 756
12 36 574
12 13 624
7 34 649
17 53 309
38 33 825
1 36 273
38 21 81
36 11 680
14 8 649
12 24 346
21 49 921
1 47 612
11 39 648
41 35 271
15 24 36
29 3 980
29 28 295
15 21 236
27 8 853
22 6 532
3 14 9...

output:

2
1 52 53 

result:

ok 2 482

Test #5:

score: 0
Accepted
time: 0ms
memory: 3488kb

input:

2 1
2 1 33

output:

1
1 2 

result:

ok 1 0

Test #6:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

123 1032
49 28 6306
70 79 6579
24 47 3306
102 114 7381
78 34 4078
31 92 2591
114 65 7836
92 59 7583
110 51 4384
84 99 439
78 48 77
23 77 6225
96 69 2939
55 112 45
48 29 4735
27 18 4242
117 97 395
71 64 2979
102 36 9531
20 86 7795
11 5 3142
114 107 1188
62 106 6321
6 71 2974
102 96 4240
82 13 7488
95...

output:

2
1 93 123 

result:

ok 2 5258

Test #7:

score: 0
Accepted
time: 12ms
memory: 4992kb

input:

1342 23134
757 512 65447
281 782 35017
179 633 86323
707 635 20673
1225 962 76138
986 59 62123
29 482 39870
90 265 65928
572 1028 18186
810 568 89715
469 998 95978
583 641 63660
261 208 37031
775 1131 33707
161 702 33733
1340 726 67611
548 583 9224
1100 208 82846
227 486 60094
1070 565 49959
1285 11...

output:

3
1 669 616 1342 

result:

ok 3 93825

Test #8:

score: 0
Accepted
time: 42ms
memory: 8620kb

input:

5313 87123
3239 37 964433
3078 247 435023
1830 493 489819
4478 1661 914186
750 2703 353434
3853 1072 285309
2117 1377 641750
1254 4366 734040
2222 2191 362794
3461 2267 359296
2514 913 627160
878 1006 709645
1767 3791 250153
4845 4041 339269
3270 2061 26968
2421 660 798388
262 1399 974636
5120 4171 ...

output:

3
1 3463 3294 5313 

result:

ok 3 878139

Test #9:

score: 0
Accepted
time: 91ms
memory: 12748kb

input:

12313 173254
4620 6513 380927
4465 6551 243296
615 9825 794381
338 11211 368032
4571 9567 634707
3731 7430 87826
8106 7718 998064
4146 7848 922789
3966 1263 331881
9179 646 948846
11893 5020 883102
5612 10513 898068
3451 3435 451139
9640 1947 1353
12271 9668 283149
9742 5631 884826
6837 2449 309976
...

output:

3
1 1402 3350 12313 

result:

ok 3 497061

Test #10:

score: -100
Wrong Answer
time: 127ms
memory: 15656kb

input:

23532 200000
21979 22532 52608855
17378 1428 55313979
12897 6506 2960978
21412 2936 26201355
1327 21400 71454522
6940 9953 7548221
15846 15164 69193724
22756 8774 49306072
10793 7975 94773768
15722 221 88298496
274 22685 29319966
21564 10196 30589888
2895 9073 93905131
8310 22526 13817682
1565 2616 ...

output:

4
1 11388 16361 18380 23532 

result:

wrong answer jury has better answer