QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875638#2746. Highway TollsWansur0 207ms24140kbC++202.8kb2025-01-30 00:19:432025-01-30 00:19:49

Judging History

This is the latest submission verdict.

  • [2025-01-30 00:19:49]
  • Judged
  • Verdict: 0
  • Time: 207ms
  • Memory: 24140kb
  • [2025-01-30 00:19:43]
  • Submitted

answer

#include "highway.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 2e5 + 12;

vector<pair<int, int>> g[maxn];
ll d1[maxn], d2[maxn];
ll a, b;
int n, m;
int pos = -1;


vector<array<int, 3>> bfs(int v, ll d[]) {
    vector<array<int, 3>> res;
    for(int i = 0; i < n; i++) {
        if(d[i] >= 0) {
            d[i] = 1e18;
        }
    }

    d[v] = 0;
    queue<int> q;
    res.push_back({v, v, -1});
    q.push(v);
    while(q.size()) {
        int u = q.front();
        q.pop();
        for(auto [to, id] : g[u]) {
            if(id < pos) continue;
            if(d[to] > d[u] + 1) {
                q.push(to);
                d[to] = d[u] + 1;
                res.push_back({u, to, id});
            }
        }
    }

    return res;
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    n = N, m = (int)U.size();
    a = A, b = B;

    for(int i = 0; i < m; i++) {
        g[U[i]].push_back({V[i], i});
        g[V[i]].push_back({U[i], i});
    }

    ll len = ask(vector<int> (m, 0));
    len /= a;
    for(int l = 0, r = m - 1; l <= r;) {
        int mid = (l + r) >> 1;
        vector<int> w(m, 0);
        for(int i = 0; i <= mid; i++) {
            w[i] = 1;
        }
        if(ask(w) > len * a) {
            pos = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }

    vector<int> ww(m, 0);
    ww[0] = 1;
    bfs(U[pos], d1);
    bfs(V[pos], d2);

    vector<int> s, t;
    for(int i = 0; i < n; i++) {
        if(d1[i] < d2[i]) {
            s.push_back(i);
        }
        if(d2[i] < d1[i]) {
            t.push_back(i);
        }
        if(d1[i] < d2[i]) d2[i] = -1;
        else if(d2[i] < d1[i]) d1[i] = -1;
    }

    auto ord = bfs(U[pos], d1);
    auto orz = bfs(V[pos], d2);

    int u = -1, v = -1;
    for(int l = 0, r = (int)ord.size() - 1; l <= r;) {
        int mid = (l + r) >> 1;
        vector<int> w(m, 0);
        for(int i = 1; i < ord.size(); i++) {
            w[ord[i][2]] = (i > mid);
        }
        for(int i = 0; i < pos; i++) {
            w[i] = 1;
        }
        if(ask(w) == len * a) {
            u = ord[mid][1];
            r = mid - 1;
        }
        else l = mid + 1;
    }
    for(int l = 0, r = (int)orz.size() - 1; l <= r;) {
        int mid = (l + r) >> 1;
        vector<int> w(m, 0);
        for(int i = 1; i < orz.size(); i++) {
            w[orz[i][2]] = (i > mid);
        }
        for(int i = 0; i < pos; i++) {
            w[i] = 1;
        }
        if(ask(w) == len * a) {
            v = orz[mid][1];
            r = mid - 1;
        }
        else l = mid + 1;
    }

    assert(u != U[pos] && u != V[pos] && v != V[pos] && v != U[pos]);
    answer(u, v);
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

100 99 1 2 0 75
15 17
47 98
19 41
22 51
38 7
96 5
47 75
28 12
6 0
25 76
0 11
32 66
97 81
23 56
32 94
46 79
18 2
0 3
44 33
89 97
49 31
43 65
56 9
71 93
87 18
12 37
94 34
73 42
66 15
15 8
27 85
3 37
57 28
74 12
69 60
91 24
82 39
60 15
67 78
1 47
19 92
86 75
30 38
86 14
50 96
38 89
50 68
70 52
63 12
12...

output:

Unauthorized output

result:


Subtask #2:

score: 0
Runtime Error

Test #13:

score: 0
Runtime Error

input:

1000 999 1 3 0 874
571 255
559 871
73 988
563 389
502 605
104 306
874 383
591 152
89 697
365 670
830 695
726 652
271 643
284 50
607 442
30 361
579 346
435 799
972 675
310 421
122 47
222 915
343 917
622 336
888 484
48 11
761 419
305 678
504 115
28 121
133 132
369 296
415 982
408 434
24 132
492 764
94...

output:

Unauthorized output

result:


Subtask #3:

score: 0
Runtime Error

Test #27:

score: 0
Runtime Error

input:

10000 9999 1 3 1402 1418
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
...

output:

Unauthorized output

result:


Subtask #4:

score: 0
Runtime Error

Test #36:

score: 0
Runtime Error

input:

1000 999 1 2 685 383
303 325
476 191
222 120
555 130
655 639
211 393
795 613
389 888
960 815
446 325
846 315
51 348
409 82
470 402
681 258
772 969
767 164
290 46
34 887
453 584
142 73
814 603
36 665
701 727
200 702
638 685
33 580
422 859
550 486
849 250
319 144
189 502
140 63
650 765
251 942
304 99
...

output:

Unauthorized output

result:


Subtask #5:

score: 0
Runtime Error

Test #61:

score: 18
Accepted
time: 13ms
memory: 5484kb

input:

10000 11000 1 2 4410 9396
4021 14
6386 7290
4635 4576
1295 5062
8655 8174
3709 4958
7062 1337
6608 2435
9704 3638
5777 2945
1125 365
2861 1023
1560 8478
1423 7827
2638 6211
1429 4399
626 6111
9981 7033
7740 7631
3904 3628
2812 6221
9946 2671
1646 6255
2653 7666
5575 3080
8314 2317
1868 7058
8177 514...

output:

Accepted: 38

result:

points 1.0

Test #62:

score: 18
Accepted
time: 11ms
memory: 5696kb

input:

10000 12000 1 2 8914 2754
434 1136
9173 573
3454 6615
2946 288
3915 3593
3828 6746
6635 665
7131 1042
4342 6970
1127 3292
8034 8501
3356 2570
1952 3736
4431 4448
8634 7879
7196 3553
611 9163
7930 5623
4745 5326
4688 2034
8854 9034
6558 9927
7478 9489
987 1460
141 7334
8768 8671
6973 4170
5359 7289
5...

output:

Accepted: 37

result:

points 1.0

Test #63:

score: 18
Accepted
time: 207ms
memory: 21544kb

input:

90000 100000 1 2 75322 63546
69499 27559
38229 1171
57605 41391
37236 5292
31433 88838
3541 3671
82244 70112
30156 75569
18991 16709
22697 35556
40077 61048
38380 81312
6303 77697
10570 27814
23603 14312
9273 54292
5697 44097
70695 35843
86903 38883
80677 25435
41667 74744
5605 14057
49672 74026
297...

output:

Accepted: 45

result:

points 1.0

Test #64:

score: 18
Accepted
time: 156ms
memory: 21608kb

input:

90000 110000 1 2 74466 67848
68097 22477
20007 34939
28196 24201
80526 63080
20627 81623
12008 46314
16911 53629
49816 193
71014 25845
13945 51574
65448 24107
44331 54812
55021 37430
60283 75844
28330 81393
21311 35513
65936 64670
33857 13492
45048 67079
39197 83746
24176 70511
67941 47342
23434 618...

output:

Accepted: 47

result:

points 1.0

Test #65:

score: 18
Accepted
time: 122ms
memory: 22940kb

input:

90000 130000 1 2 56305 39836
1604 82119
43477 2753
47523 67309
71136 15561
20783 44710
39073 31749
6828 14770
47157 11662
80463 70032
17608 25155
73309 2097
60275 65633
74034 14638
87431 58865
68932 58173
21478 53704
52412 44267
52702 56477
56226 71197
2970 7354
39550 88510
26905 54644
55560 86979
7...

output:

Accepted: 48

result:

points 1.0

Test #66:

score: 18
Accepted
time: 186ms
memory: 24140kb

input:

90000 130000 1 2 63390 29918
43935 67677
64814 71435
7795 86165
9178 14941
49328 26067
87813 3426
41778 47453
3316 27333
68266 87896
89807 74352
30386 69164
19434 74827
12972 47452
88521 54592
20891 32716
86567 2892
61130 13173
75178 34646
9395 58963
13646 4810
73395 42900
70573 42572
66106 1489
823...

output:

Accepted: 49

result:

points 1.0

Test #67:

score: 18
Accepted
time: 138ms
memory: 23836kb

input:

90000 130000 1 2 11022 89395
75693 84971
30696 47119
58426 19067
34383 87899
35529 14786
11402 88537
14569 85256
89788 26671
45642 5813
32553 68443
23961 68708
1437 58824
49694 46233
62923 59227
19534 68125
73800 44065
65575 58256
38526 12890
16338 84303
16848 7588
49529 365
79859 56
76961 25871
356...

output:

Accepted: 48

result:

points 1.0

Test #68:

score: 0
Runtime Error

input:

90000 130000 1 2 42568 68186
44784 80303
10319 1023
14043 15412
83359 89919
71326 14771
8602 21355
35485 15804
80662 34042
18358 26369
13635 59420
65758 17748
2070 79076
20146 16442
6084 46290
65228 51742
68485 26027
75950 12124
82601 74582
61984 66774
70563 73800
9064 63841
72933 29722
40428 38750
...

output:

Unauthorized output

result:


Subtask #6:

score: 0
Runtime Error

Test #82:

score: 31
Accepted
time: 6ms
memory: 5680kb

input:

10000 11000 1 3 242 6594
7153 1171
3833 5240
2223 8238
7347 5616
7332 7717
1485 7260
2323 3839
7359 9719
6973 7446
9821 1553
4652 663
3200 30
9465 9801
5461 4480
2298 513
5950 7473
4726 6408
7990 2674
4736 7663
9124 7932
1022 807
6870 6840
8507 62
4036 7781
1867 4826
9093 6486
9303 7974
5399 4503
90...

output:

Accepted: 38

result:

points 1.0

Test #83:

score: 31
Accepted
time: 16ms
memory: 5768kb

input:

10000 12000 2 3 4857 2452
4361 665
4690 1770
2293 1547
4473 1035
7838 4758
3370 7154
5965 4793
6751 7912
108 311
7994 7516
930 1881
3688 8582
8788 3182
9538 8770
3705 6854
1082 7659
3142 3131
1749 6271
6129 8039
7431 848
4893 206
8341 6642
1088 100
8427 6334
1946 6672
1221 501
1019 7308
7802 538
658...

output:

Accepted: 37

result:

points 1.0

Test #84:

score: 31
Accepted
time: 63ms
memory: 21680kb

input:

90000 101000 4 5 56091 53745
50551 69009
41341 69902
10324 82455
21704 16360
38034 86326
20751 84303
12519 5756
26410 49921
61625 87388
41276 27250
64383 64446
60811 69266
63192 35949
67415 4762
49420 53900
52643 74779
55133 85578
25210 63881
65649 42267
33905 13198
1353 72860
26338 81080
21165 7860...

output:

Accepted: 48

result:

points 1.0

Test #85:

score: 31
Accepted
time: 134ms
memory: 21928kb

input:

90000 105000 3 99 86503 23751
17425 85839
2827 42783
68907 30080
9311 44087
34334 16980
62285 50804
34671 25544
58671 73724
78917 86481
69381 36611
33743 44518
80626 1026
71227 75339
77255 36925
72285 38384
23232 15852
30552 36813
78564 53390
5032 9979
45179 43133
19536 17869
78481 76272
8052 50389
...

output:

Accepted: 49

result:

points 1.0

Test #86:

score: 31
Accepted
time: 183ms
memory: 21904kb

input:

90000 110000 3 999 73530 26097
15598 49512
19727 2591
44549 68835
83814 37610
26854 23699
34946 22039
31851 70554
81204 72799
43004 16235
9657 58241
84910 45683
57949 20644
64023 60528
16622 63229
3705 86052
2665 70592
46261 70450
18172 65840
55300 80502
86781 30316
89894 23688
60142 285
77211 24461...

output:

Accepted: 49

result:

points 1.0

Test #87:

score: 0
Runtime Error

input:

90000 130000 4 111 86771 33394
68780 6781
47630 19590
38335 80190
30551 84588
13107 11858
17336 72950
68287 35327
1788 40577
34803 64419
29337 88444
33354 75479
25641 82542
37999 17902
7122 73725
74971 52218
43234 68889
88640 68809
63697 83358
87572 59823
56081 59311
65971 18204
71515 38052
28070 59...

output:

Unauthorized output

result: