QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#532740#5081. Forbidden TurnsBongoCatEnjoyer#AC ✓542ms60776kbC++142.0kb2024-08-25 10:48:462024-08-25 10:48:46

Judging History

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

  • [2024-08-25 10:48:46]
  • 评测
  • 测评结果:AC
  • 用时:542ms
  • 内存:60776kb
  • [2024-08-25 10:48:46]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define forn(i, n) for (ll i = 0; i < n; ++i)
#define forr(i, s, n) for (ll i = s; i < n; ++i)
#define fori(i, s, n) for (ll i = s; i > n; --i)
#define fora(i, n) for (auto i: n)
#define vi vector<int>
#define vll vector<ll>
#define prints(n) cout << (n) << " "
#define println(n) cout << (n) << "\n"

const int MOD = 998244353;
// const int MOD = 1e9 + 7;

void solve() {
    ll m, n, k; cin >> m >> n >> k;
    ll s, t; cin >> s >> t;

    vector<vector<pair<ll, ll>>> adj(n, vector<pair<ll, ll>>());

    map<pair<ll, ll>, ll> mp; 
    forn(i, m) {
        ll u, v, w; cin >> u >> v >> w;
        adj[u].push_back({v, w});

        mp[{u, v}] = i;
    }

    map<pair<int, int>, set<int>> forb;
    forn(i, k) {
        ll a, b, c; cin >> a >> b >> c;
        if (forb.find({a, b}) == forb.end()) forb[{a, b}] = set<int>();
        forb[{a, b}].insert(c);
    }

    priority_queue<pair<int, pair<int, int>>> pq;

    pq.push({0, {-1, s}});

    set<int> vis[n+5];

    while (!pq.empty()) {
        pair<int, pair<int, int>> p = pq.top();
        int w = p.first;
        int prev = p.second.first;
        int cur = p.second.second;
        pq.pop();

        if (cur == t) {
            cout << -w << '\n';
            return;
        }

        if (vis[cur].count(prev) || vis[cur].count(-1)) {
            continue;
        }
        if (forb.count({prev, cur})) {
            vis[cur].insert(prev);
        }
        else {
            vis[cur].insert(-1);
        }

        set<int> curforb = forb[{prev, cur}];
        for(auto x: adj[cur]) {
            if (curforb.count(x.first)) continue;
            pq.push({w - x.second, {cur, x.first}});
        }
    }

    cout << -1 << '\n';
    
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

详细

Test #1:

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

input:

9 7 3
3 2
6 3 2
3 0 3
0 1 12
1 0 4
1 2 2
1 5 4
4 1 8
5 4 7
5 2 5
0 1 2
4 1 5
1 5 2

output:

36

result:

ok single line: '36'

Test #2:

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

input:

4 4 1
0 3
0 1 2
1 2 3
0 2 7
2 3 10
0 1 2

output:

17

result:

ok single line: '17'

Test #3:

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

input:

4 4 0
0 3
0 1 2
1 2 3
0 2 7
2 3 10

output:

15

result:

ok single line: '15'

Test #4:

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

input:

4 4 1
1 0
1 2 3
2 3 10
3 2 12
2 0 7
1 2 0

output:

32

result:

ok single line: '32'

Test #5:

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

input:

13 8 5
0 5
0 2 3
2 1 7
4 2 10
2 3 10
3 2 12
2 5 10
3 6 10
6 7 5
7 3 5
6 4 10
4 1 0
1 4 10
4 6 10
0 2 1
0 2 5
3 2 5
2 3 2
6 4 2

output:

63

result:

ok single line: '63'

Test #6:

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

input:

4 4 2
1 0
1 2 3
2 3 10
3 2 12
2 0 7
1 2 0
2 3 2

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4 4 0
1 0
1 2 3
2 3 2
3 2 3
2 0 7

output:

10

result:

ok single line: '10'

Test #8:

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

input:

0 1 0
0 0

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 49ms
memory: 21424kb

input:

59996 30000 29997
0 29999
0 1 3
1 29999 7
1 2 1
2 1 1
2 3 1
3 2 1
3 4 1
4 3 1
4 5 1
5 4 1
5 6 1
6 5 1
6 7 1
7 6 1
7 8 1
8 7 1
8 9 1
9 8 1
9 10 1
10 9 1
10 11 1
11 10 1
11 12 1
12 11 1
12 13 1
13 12 1
13 14 1
14 13 1
14 15 1
15 14 1
15 16 1
16 15 1
16 17 1
17 16 1
17 18 1
18 17 1
18 19 1
19 18 1
19 2...

output:

60004

result:

ok single line: '60004'

Test #10:

score: 0
Accepted
time: 128ms
memory: 20696kb

input:

54776 10000 149059
0 9999
0 1168 720
0 7849 347
0 5301 937
0 1176 113
0 4762 833
0 6595 630
0 5846 548
0 528 878
1 3794 680
1 5036 171
1 4938 977
1 3180 522
1 9790 3
1 2139 221
1 3003 470
2 1054 534
2 5405 899
2 8279 740
2 1749 864
2 4634 773
2 7027 960
2 8151 321
2 4893 201
3 960 939
4 2349 671
5 6...

output:

2041

result:

ok single line: '2041'

Test #11:

score: 0
Accepted
time: 118ms
memory: 21008kb

input:

54727 10000 149795
0 9999
0 2611 51
0 6360 105
0 9596 66
0 7534 845
0 8007 758
0 1455 356
1 5761 949
1 5075 518
1 9029 436
1 432 235
1 4260 356
1 2845 870
1 5620 793
1 8169 483
2 4993 131
2 5942 50
2 3295 965
2 8977 538
3 8231 754
3 3852 321
3 3800 424
3 1731 493
4 5578 42
4 4697 337
4 3900 54
4 444...

output:

2572

result:

ok single line: '2572'

Test #12:

score: 0
Accepted
time: 136ms
memory: 22360kb

input:

55101 10000 151145
0 9999
0 8800 169
0 1752 969
1 6634 310
1 3693 284
1 1650 910
1 5991 323
1 2499 279
1 5189 154
1 4153 425
2 5566 738
2 2769 947
3 7442 71
3 4856 367
3 1109 398
3 6801 846
4 8109 118
4 290 414
4 315 259
4 4814 323
4 4821 135
5 2971 275
5 8576 605
6 7061 788
6 6608 336
6 1414 671
6 ...

output:

4445

result:

ok single line: '4445'

Test #13:

score: 0
Accepted
time: 127ms
memory: 21556kb

input:

54756 10000 150207
0 9999
0 1148 773
0 5763 985
0 2835 602
0 977 30
0 9223 600
0 2104 51
0 2094 617
1 4084 55
1 8160 512
1 2837 284
2 3303 473
2 9720 598
2 3700 191
2 9804 546
2 5114 882
2 7947 903
2 4817 499
3 5985 705
3 709 686
3 7579 496
3 172 434
3 7311 760
3 4812 52
4 609 174
5 1269 115
5 4314 ...

output:

3096

result:

ok single line: '3096'

Test #14:

score: 0
Accepted
time: 127ms
memory: 21136kb

input:

54656 10000 150741
0 9999
0 1511 252
0 7148 940
0 486 614
0 4770 773
0 2790 17
0 3626 76
0 9832 174
0 4562 827
1 5855 35
1 9290 513
1 2982 35
1 2854 751
1 6897 316
2 4990 733
2 5224 761
2 3283 21
3 6955 163
3 4823 213
3 2286 385
3 4033 965
4 9836 810
4 9699 309
5 1609 184
5 4014 366
6 6616 824
6 430...

output:

2876

result:

ok single line: '2876'

Test #15:

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

input:

6 5 1
1 0
1 2 3
2 3 10
3 2 12
2 0 7
3 4 20
4 0 30
1 2 0

output:

32

result:

ok single line: '32'

Test #16:

score: 0
Accepted
time: 156ms
memory: 22440kb

input:

54620 10000 148088
0 9999
0 8788 329
0 5514 152
0 8678 225
0 373 846
0 3314 720
0 8746 235
0 7183 822
0 6125 619
1 8172 190
2 4792 153
2 1637 513
2 8863 382
2 5682 160
2 1245 423
3 2635 430
3 7675 950
3 1297 203
3 7691 368
3 2102 619
3 4561 911
4 9702 137
4 3518 713
4 3199 10
5 6043 169
5 5485 427
5...

output:

-1

result:

ok single line: '-1'

Test #17:

score: 0
Accepted
time: 293ms
memory: 36636kb

input:

100499 20000 252177
0 19999
0 4909 501
0 7476 72
0 213 419
0 1345 437
0 15774 245
0 19177 110
0 14978 643
1 3596 825
1 1551 83
1 5153 659
1 19670 367
1 14230 690
1 14114 887
1 4960 258
1 19970 664
2 3014 89
2 3704 551
2 4713 838
2 19776 812
2 2058 634
2 10576 105
2 6594 344
2 17514 686
2 18313 144
3...

output:

5221

result:

ok single line: '5221'

Test #18:

score: 0
Accepted
time: 244ms
memory: 33928kb

input:

100285 20000 253404
0 19999
0 4254 100
0 15222 926
0 12348 85
0 18968 814
0 16722 152
0 10524 675
0 5138 145
0 6237 142
0 2540 29
0 11488 316
1 6385 540
1 18451 118
1 8972 753
1 16713 771
1 5968 409
2 6455 750
2 14274 264
2 14479 678
2 18501 760
2 14550 255
2 440 941
4 8620 550
4 13996 430
4 11503 2...

output:

3508

result:

ok single line: '3508'

Test #19:

score: 0
Accepted
time: 278ms
memory: 35864kb

input:

99992 20000 253335
0 19999
0 8255 809
0 3678 983
0 10202 197
0 8622 393
0 6412 513
0 16316 386
0 3764 735
1 10444 620
1 17083 630
1 11119 466
1 1225 624
1 16144 122
1 15830 989
1 17985 6
1 13278 79
1 2046 181
2 4592 920
2 11084 31
2 9617 194
2 13251 529
2 19471 474
2 2815 545
3 13458 7
3 4253 436
3 ...

output:

4648

result:

ok single line: '4648'

Test #20:

score: 0
Accepted
time: 241ms
memory: 33120kb

input:

99717 20000 247973
0 19999
0 9436 682
0 8559 374
0 19400 453
0 11207 429
0 6056 453
0 6013 179
0 12699 988
0 19103 35
1 15305 25
1 17933 126
1 11215 696
1 19216 1000
1 16966 238
1 80 802
1 10058 496
1 7591 843
1 15526 204
2 19411 813
3 14998 586
3 17342 655
4 501 798
4 19523 977
4 6334 938
5 14088 1...

output:

2710

result:

ok single line: '2710'

Test #21:

score: 0
Accepted
time: 238ms
memory: 33500kb

input:

100090 20000 247340
0 19999
0 14430 821
0 12070 934
0 10224 601
2 5406 669
2 17051 351
2 19716 574
2 15929 494
2 16023 600
3 7632 312
3 7322 276
3 9832 189
3 2065 720
4 898 949
4 13807 865
4 7870 371
4 4133 953
4 11288 718
4 14981 287
4 17165 597
5 7245 485
6 16271 800
6 18484 830
6 13913 664
6 1585...

output:

4198

result:

ok single line: '4198'

Test #22:

score: 0
Accepted
time: 233ms
memory: 33876kb

input:

100333 20000 253847
0 19999
0 4558 679
0 32 669
1 3597 719
1 1059 439
1 18976 206
1 17126 802
1 12710 213
1 6219 8
2 4533 253
2 13974 148
2 10008 702
2 2907 476
2 14689 259
2 15681 773
3 13878 537
3 18752 969
4 17254 804
4 5280 851
4 9723 816
4 9873 195
4 17393 52
4 15740 532
5 9583 966
5 16931 314
...

output:

4282

result:

ok single line: '4282'

Test #23:

score: 0
Accepted
time: 238ms
memory: 33584kb

input:

99415 20000 247270
0 19999
0 17753 435
0 3769 784
0 14821 77
0 15948 956
0 12628 755
0 6834 759
0 1465 865
0 8841 436
1 2024 797
1 16892 505
1 9941 825
2 6212 117
2 18097 767
2 12725 290
2 12100 282
2 13471 976
2 724 989
2 7368 730
2 7704 264
2 10011 602
3 10292 242
4 18438 76
4 2786 777
4 13198 806...

output:

3652

result:

ok single line: '3652'

Test #24:

score: 0
Accepted
time: 240ms
memory: 33704kb

input:

100086 20000 250032
0 19999
0 8764 438
0 5784 974
1 13571 515
2 19393 158
2 3706 356
3 1834 732
3 17282 589
3 1533 514
3 2863 14
3 9103 608
3 17238 344
3 16470 592
3 16639 641
3 5254 308
3 17414 885
5 811 361
5 12102 4
5 3140 17
5 2367 727
5 18607 440
6 6062 774
6 15731 635
7 16272 53
7 8033 401
7 3...

output:

4384

result:

ok single line: '4384'

Test #25:

score: 0
Accepted
time: 275ms
memory: 35188kb

input:

99662 20000 248395
0 19999
0 10118 469
0 14790 675
2 17863 520
2 19318 409
2 18256 263
2 13319 411
2 19237 664
2 12098 151
2 655 499
3 13943 801
3 13181 51
3 5386 790
3 13107 300
3 3071 120
3 10847 500
3 15094 368
3 16245 968
3 10440 902
3 17586 266
4 14461 275
4 13097 854
4 6205 27
4 18855 767
4 63...

output:

5611

result:

ok single line: '5611'

Test #26:

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

input:

7 5 2
1 0
1 2 3
2 3 10
3 2 12
2 0 7
3 4 20
4 0 30
4 3 3
1 2 0
2 3 2

output:

55

result:

ok single line: '55'

Test #27:

score: 0
Accepted
time: 414ms
memory: 48708kb

input:

150086 30000 377004
0 29999
0 7017 866
0 17935 860
0 25861 553
0 2326 888
0 10317 681
1 17333 263
1 26103 517
1 25852 84
1 20677 545
1 27100 52
1 14519 930
1 26975 459
1 15317 20
2 16898 487
2 6874 120
2 25323 859
2 23144 846
2 19019 315
3 13597 246
4 23206 20
4 7288 975
4 27265 967
4 14904 379
5 13...

output:

3408

result:

ok single line: '3408'

Test #28:

score: 0
Accepted
time: 394ms
memory: 48176kb

input:

150075 30000 379971
0 29999
0 21471 838
0 20323 412
0 21443 362
0 11315 283
0 29832 535
0 3530 511
0 17214 444
0 13373 977
0 14228 254
0 28709 578
1 6606 281
1 17191 840
1 23705 314
1 326 740
1 9305 960
1 23428 903
1 23904 151
1 2538 221
1 8580 33
1 14860 587
2 19222 209
2 26555 470
2 28039 88
2 275...

output:

2761

result:

ok single line: '2761'

Test #29:

score: 0
Accepted
time: 374ms
memory: 47756kb

input:

149963 30000 373755
0 29999
0 5499 956
0 18399 900
0 16446 102
3 12363 607
3 11578 659
3 11777 412
3 8572 275
3 19824 420
4 6808 364
4 22851 414
4 11462 846
4 23846 235
5 14119 85
5 17215 341
5 11373 462
5 13176 526
5 19279 185
5 27159 983
5 16560 221
5 23987 939
6 21917 397
6 1882 667
6 283 984
6 2...

output:

3229

result:

ok single line: '3229'

Test #30:

score: 0
Accepted
time: 410ms
memory: 50408kb

input:

149888 30000 375215
0 29999
0 21239 351
0 8581 738
0 17775 369
1 27168 377
1 28084 786
1 14244 623
1 18644 778
1 1208 222
2 3064 683
2 19744 632
2 12792 662
3 1226 333
3 19228 674
3 29342 131
3 23919 421
3 3502 242
3 6695 181
3 9912 283
3 1308 611
3 18119 510
4 21374 599
4 17161 50
4 19097 52
5 1519...

output:

4846

result:

ok single line: '4846'

Test #31:

score: 0
Accepted
time: 370ms
memory: 47436kb

input:

149852 30000 373545
0 29999
1 28864 590
1 15880 90
1 2104 263
1 2158 599
1 26362 871
1 9557 426
1 22236 973
2 21297 578
2 13493 920
2 25748 185
2 6281 224
2 23862 544
2 8166 691
2 8902 200
2 26616 927
2 13426 956
4 2098 684
4 19445 486
4 25706 108
4 14203 714
4 4985 420
4 21436 653
5 8512 486
5 1149...

output:

-1

result:

ok single line: '-1'

Test #32:

score: 0
Accepted
time: 386ms
memory: 49356kb

input:

149610 30000 371424
0 29999
0 21594 406
0 14642 846
0 27294 803
0 770 169
0 10597 927
0 20942 537
0 22971 468
0 15068 35
0 26190 222
0 15904 767
1 18156 264
2 1484 416
2 18695 561
3 19438 111
3 22176 934
3 1743 78
3 597 747
3 3103 11
3 17278 379
3 8961 134
3 29892 970
4 13574 279
4 21194 37
4 6690 8...

output:

4052

result:

ok single line: '4052'

Test #33:

score: 0
Accepted
time: 447ms
memory: 52440kb

input:

151474 30000 383060
0 29999
0 18089 984
0 14178 594
1 19630 224
1 28841 60
1 2792 439
1 29789 798
2 22049 676
2 5019 538
2 3275 292
2 11063 838
2 19377 164
2 22684 129
3 974 374
3 28491 357
4 27122 837
4 28192 413
4 2663 895
4 22806 785
4 13274 295
4 19018 878
5 339 868
5 667 205
5 25696 580
5 3455 ...

output:

6213

result:

ok single line: '6213'

Test #34:

score: 0
Accepted
time: 400ms
memory: 49200kb

input:

149536 30000 373566
0 29999
0 729 808
0 2056 883
0 19108 560
0 5306 10
0 2300 604
2 4359 480
2 10917 132
2 29369 927
2 20111 487
2 13180 540
2 2749 760
2 21657 232
3 20657 530
3 25722 153
3 5909 468
3 16160 84
3 27183 273
3 25219 820
3 662 48
3 5452 382
4 1063 296
4 18912 565
4 28303 140
4 13061 636...

output:

4296

result:

ok single line: '4296'

Test #35:

score: 0
Accepted
time: 447ms
memory: 51392kb

input:

150291 30000 374286
0 29999
0 178 521
0 1131 106
0 8225 996
0 11487 465
0 11541 774
0 2397 659
0 12282 558
0 27884 335
0 29072 264
2 5266 990
2 19318 470
2 25962 440
2 21030 400
2 14986 750
2 4008 744
2 12469 171
2 10017 838
3 6943 577
3 26773 915
3 4800 976
3 16225 666
3 8576 750
3 13448 952
3 2990...

output:

5054

result:

ok single line: '5054'

Test #36:

score: 0
Accepted
time: 373ms
memory: 48168kb

input:

150597 30000 377534
0 29999
0 20603 93
0 8291 612
0 21907 766
0 2937 316
0 12651 870
0 12540 407
0 132 652
0 28120 506
0 17646 658
0 21454 212
1 23996 643
1 28551 385
1 13108 529
1 5680 338
1 106 772
1 14303 815
1 11290 473
1 4452 152
1 25118 720
1 14800 913
2 1643 36
2 26156 759
2 8526 419
2 26619 ...

output:

2315

result:

ok single line: '2315'

Test #37:

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

input:

7 5 2
1 1
1 2 3
2 3 10
3 2 12
2 0 7
3 4 20
4 0 30
4 3 3
1 2 0
2 3 2

output:

0

result:

ok single line: '0'

Test #38:

score: 0
Accepted
time: 542ms
memory: 60776kb

input:

165113 30000 455900
0 29999
0 15103 975
0 2645 226
0 4732 174
0 9052 353
0 21524 844
0 5194 865
1 9378 218
1 27623 91
1 2190 888
1 21528 815
1 12042 569
2 24855 712
2 339 349
2 25356 334
2 29918 454
2 4894 351
3 6234 816
3 16972 638
3 23107 170
3 11904 909
3 18490 205
4 26133 285
4 29709 86
4 8339 6...

output:

4380

result:

ok single line: '4380'

Test #39:

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

input:

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

output:

62

result:

ok single line: '62'

Test #40:

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

input:

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

output:

82

result:

ok single line: '82'

Test #41:

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

input:

11 8 4
0 5
0 2 3
2 1 7
1 4 10
4 2 10
2 3 10
3 2 12
2 5 10
3 6 10
6 7 5
7 3 5
6 4 10
0 2 1
0 2 5
3 2 5
2 3 2

output:

53

result:

ok single line: '53'

Test #42:

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

input:

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

output:

63

result:

ok single line: '63'

Test #43:

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

input:

11 8 5
0 5
0 2 3
2 1 7
4 2 10
2 3 10
3 2 12
2 5 10
3 6 10
6 7 5
7 3 5
6 4 10
4 1 0
0 2 1
0 2 5
3 2 5
2 3 2
6 4 2

output:

-1

result:

ok single line: '-1'