QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#612085#2766. Unique Citiesmakrav0 591ms200084kbC++207.2kb2024-10-05 05:05:412024-10-05 05:05:43

Judging History

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

  • [2024-10-05 05:05:43]
  • 评测
  • 测评结果:0
  • 用时:591ms
  • 内存:200084kb
  • [2024-10-05 05:05:41]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

template<typename T>
struct sparsetable {
    int n;
    vector<T> arr;
    vector<vector<T>> sp;
    function<T(T, T)> comp;
    sparsetable() = default;
    sparsetable(int n_, vector<T> arr_, function<T(T, T)> f) {
        n = n_;
        arr = arr_;
        comp = f;
        build();
    }

    void build() {
        int lg = (int) log2(n) + 1;
        sp.assign(lg, vector<T>(n));
        for (int i = 0; i < n; i++) sp[0][i] = arr[i];
        for (int i = 1; i <= lg; i++) {
            for (int j = 0; j + (1 << i) - 1 < n; j++) {
                sp[i][j] = comp(sp[i - 1][j], sp[i - 1][j + (1 << (i - 1))]);
            }
        }
    }

    T get(int l, int r) {
        int lg = 31 - __builtin_clz(r - l + 1);
        return comp(sp[lg][l], sp[lg][r - (1 << lg) + 1]);
    }
};

const int LOGMAX = 20;

void solve() {
    int n, m; cin >> n >> m;
    vector<int> c(n);
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    for (int i = 0; i < n; i++) cin >> c[i];

    vector<int> tin(n), tout(n);
    vector<int> hs, vts, h(n);
    auto dfs0 = [&](int v, int p, auto&&self) -> void {
        tin[v] = sz(hs);
        hs.pb(h[v]);
        vts.pb(v);
        for (auto &u : g[v]) {
            if (u != p) {
                h[u] = h[v] + 1;
                self(u, v, self);
                hs.pb(h[v]);
                vts.pb(v);
            }
        }
        tout[v] = sz(hs) - 1;
    };
    dfs0(0, 0, dfs0);
    vector<pair<int, int>> lol;
    for (int i = 0; i < sz(hs); i++) lol.pb({hs[i], i});
    sparsetable<pair<int, int>> sp(sz(hs), lol, [](pair<int, int> x, pair<int, int> y) {
        return (x.first < y.first ? x : y);
    });
    vector<int> vt_num(3 * n, -1);

    auto is_par = [&](int v, int u) {
        return tin[v] <= tin[u] && tout[u] <= tout[v];
    };
    auto lca = [&](int u, int v) {
        if (is_par(u, v)) return u;
        if (is_par(v, u)) return v;
        auto rs = sp.get(min(tout[v], tout[u]), max(tin[v], tin[u]));
        return vts[rs.second];
    };
    auto dist = [&](int u, int v) {
        if (u >= n) u = vt_num[u];
        if (v >= n) v = vt_num[v];
        return h[u] + h[v] - 2 * h[lca(u, v)];
    };

    vector<int> nxt(3 * n);
    vector<vector<int>> up(LOGMAX, vector<int>(3 * n, -1));
    vector<int> maxd(n);

    auto jump = [&](int vt, int v, int maxd) {
        if (vt == -1) return -1;
        // find min jump from vt in graph nxt, where dist(v, jump) > maxd
        for (int i = LOGMAX - 1; i >= 0; i--) {
            if (up[i][vt] != -1 && dist(v, up[i][vt]) <= maxd) {
                vt = up[i][vt];
            }
        }
        if (vt != -1 && dist(v, vt) > maxd) return vt;
        if (up[0][vt] != -1) return up[0][vt];
        return (dist(v, vt) > maxd ? vt : -1);
    };

    auto dfs1 = [&](int v, int p, auto&&self) -> void {
        maxd[v] = h[v];
        vector<int> sons;
        for (auto &u : g[v]) {
            if (u != p) {
                self(u, v, self);
                sons.pb(u);
            }
        }
        if (sons.empty()) {
            nxt[v] = -1;
            up[0][v] = nxt[v];
            for (int i = 1; i < LOGMAX; i++) {
                if (up[i - 1][v] == -1) up[i][v] = -1;
                else {
                    up[i][v] = up[i - 1][up[i - 1][v]];
                }
            }
            return;
        }
        int bs = sons[0];
        for (int i = 1; i < sz(sons); i++) {
            if (maxd[sons[i]] > maxd[bs]) bs = sons[i];
        }
        int md2 = 0;
        for (int son : sons) {
            if (son != bs) md2 = max(md2, maxd[son] - h[v]);
        }
        nxt[v] = jump(bs, v, md2);
        up[0][v] = nxt[v];
        maxd[v] = maxd[bs];
        for (int i = 1; i < LOGMAX; i++) {
            if (up[i - 1][v] == -1) up[i][v] = -1;
            else {
                up[i][v] = up[i - 1][up[i - 1][v]];
            }
        }
    };

    dfs1(0, 0, dfs1);
    vector<int> final_vertex(n);
    int curvts = 0;
    auto dfs2 = [&](int v, int p, int pvert, int upp, auto&&self) -> void {
        if (maxd[v] - h[v] > upp) final_vertex[v] = jump(v, v, upp);
        else {
            final_vertex[v] = jump(pvert, v, maxd[v] - h[v]);
        }

        vector<int> sons;
        for (auto &u : g[v]) {
            if (u != p) sons.pb(u);
        }
        if (sons.empty()) {
            return;
        }
        sort(all(sons), [&](int i, int j) {
            return maxd[i] > maxd[j];
        });
        if (sons.size() == 1) {
            int nv = n + curvts;
            vt_num[nv] = v;
            nxt[nv] = pvert;
            up[0][nv]=nxt[nv];
            for (int i = 1; i < LOGMAX; i++) {
                up[i][nv] = (up[i - 1][nv] == -1 ? -1 : up[i - 1][up[i - 1][nv]]);
            }

            curvts++;
            self(sons[0], v, nv, upp + 1, self);
            return;
        }
        for (int i = 0; i < sz(sons); i++) {
            int vt2 = (i == 0 ? sons[1] : sons[0]);
            int nv = n + curvts;
            vt_num[nv] = v;
            curvts++;
            if (maxd[vt2] - h[v] > upp) {
                nxt[nv] = jump(vt2, v, upp);
            } else {
                nxt[nv] = jump(pvert, v, maxd[vt2] - h[v]);
            }

            up[0][nv]=nxt[nv];
            for (int i = 1; i < LOGMAX; i++) {
                up[i][nv] = (up[i - 1][nv] == -1 ? -1 : up[i - 1][up[i - 1][nv]]);
            }
            self(sons[i], v, nv, max(upp, maxd[vt2] - h[v]) + 1, self);
        }
    };
    dfs2(0, 0, -1, 0, dfs2);
    vector<vector<int>> G(3 * n);
    for (int i = 0; i < 3 * n; i++) {
        if (nxt[i] != -1) G[nxt[i]].pb(i);
    }

    vector<int> cost(3 * n), used(3 * n);
    unordered_map<int, int> cnt;
    auto dfs3 = [&](int v, auto&&self) -> void {
        used[v] = 1;
        for (auto &u : G[v]) {
            if (!used[u]) {
                int addd = 0;
                if (cnt[c[vt_num[u]]] == 0) addd = 1;
                cnt[c[vt_num[u]]]++;
                cost[u] = cost[v] + addd;
                self(u, self);
                cnt[c[vt_num[u]]]--;
            }
        }
    };
    for (int i = 0;i<n;i++)vt_num[i]=i;
    for (int i = 0; i < 3 * n; i++) {
        if (nxt[i] == -1 && vt_num[i] != -1) {
            cnt[c[vt_num[i]]]++;
            cost[i] = 1;
            dfs3(i, dfs3);
            cnt[c[vt_num[i]]]--;
        }
    }
    // for (int i = 0; i < n; i++) cout << nxt[i] << ' ';
    // cout << '\n';
    for (int i = 0; i < n; i++) cout << (final_vertex[i] == -1 ? 0 : cost[final_vertex[i]]) << '\n';
}

signed main() {
    int tt = 1;
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else
        ios::sync_with_stdio(false); 
        cin.tie(0); cout.tie(0);
    #endif

    while (tt--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 4
Accepted
time: 0ms
memory: 3640kb

input:

2 1
1 2
1 1

output:

1
1

result:

ok 2 lines

Test #2:

score: 4
Accepted
time: 2ms
memory: 5020kb

input:

1842 848
740 1093
1299 922
801 1560
265 1664
1043 65
1430 427
80 233
4 1238
1623 1473
1569 274
953 1485
1259 649
1671 1409
246 542
742 1517
720 1120
1527 1328
1167 1531
1056 1130
673 1222
192 980
1393 913
446 688
135 23
1065 1787
978 1481
1765 1720
310 202
1406 1451
475 523
104 774
1531 829
169 396
...

output:

1
1
1
0
0
0
2
0
3
0
2
1
0
3
0
0
0
2
0
0
4
2
0
2
4
0
0
1
1
1
2
1
1
1
0
0
1
3
0
1
2
0
1
1
4
0
1
1
1
3
0
2
1
0
1
1
0
0
2
1
1
2
1
1
1
0
3
0
1
2
0
0
1
0
0
0
1
1
3
1
4
3
1
2
2
0
1
3
0
2
1
0
1
1
1
1
1
2
3
1
0
1
2
1
0
1
2
4
1
3
0
0
0
4
0
1
1
2
2
2
3
0
5
2
1
5
0
1
1
0
0
2
0
2
0
2
4
0
1
0
3
0
3
0
0
2
0
1
0
2
...

result:

ok 1842 lines

Test #3:

score: 4
Accepted
time: 1ms
memory: 4516kb

input:

951 908
777 679
676 510
34 425
424 889
78 4
924 408
151 905
399 942
606 776
275 332
616 900
513 372
911 130
465 430
126 303
380 603
506 505
592 38
917 270
435 815
591 773
63 66
417 642
301 693
814 454
735 671
899 674
925 846
254 898
845 569
703 659
707 241
482 715
646 282
274 925
861 374
699 488
903...

output:

302
286
491
486
478
563
380
32
497
563
115
30
581
428
510
491
374
565
242
418
469
550
410
229
499
386
274
588
487
276
279
536
445
203
483
56
565
361
129
140
533
437
229
68
442
559
570
502
493
212
588
96
330
405
262
526
464
516
258
541
554
264
475
441
544
476
406
222
468
397
531
591
406
39
320
198
60...

result:

ok 951 lines

Test #4:

score: 0
Wrong Answer
time: 2ms
memory: 5108kb

input:

1817 365
1516 74
1811 1805
1036 311
1769 1663
1029 473
1596 310
337 888
324 426
385 315
1780 1684
1750 794
895 1029
1108 1194
566 613
489 1230
1727 1520
170 302
731 1171
591 295
1165 1233
304 835
1607 404
1035 1675
158 735
1553 1764
1390 1078
197 980
1176 1626
16 1218
1530 1146
1692 1477
1513 574
32...

output:

0
296
202
198
53
325
1
322
242
101
132
0
327
219
323
27
1
152
252
67
288
43
157
207
156
288
1
237
0
79
218
313
322
202
318
209
2
218
274
54
304
197
16
313
138
0
221
262
113
297
233
195
1
195
281
287
300
158
266
0
0
267
328
294
252
290
0
4
191
1
3
266
322
2
1
5
0
1
0
0
321
308
0
327
249
3
319
252
274...

result:

wrong answer 2nd lines differ - expected: '129', found: '296'

Subtask #2:

score: 0
Wrong Answer

Test #33:

score: 32
Accepted
time: 133ms
memory: 94344kb

input:

115391 1
32067 50006
1710 5850
21016 66364
72998 34367
24783 10670
49950 93666
81835 81234
53480 68963
87357 43320
93905 30509
72528 92224
520 100511
54804 2917
58490 23858
93643 87530
90737 65205
60740 110812
9553 90266
70028 67222
108045 88982
35584 110286
53518 21733
108735 26404
108228 109796
92...

output:

1
1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
0
0
1
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
0
1
1
0
1
1
1
1
1
1
1
1
0
1
0
1
1
0
1
1
1
1
1
0
1
1
1
1
0
1
1
0
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 115391 lines

Test #34:

score: 32
Accepted
time: 236ms
memory: 114240kb

input:

114976 1
74053 36053
62978 89255
32367 21913
113882 44280
60815 35782
107811 95272
109039 78845
22484 41688
1781 111596
111506 59375
19869 45586
84990 81214
38638 90205
14928 14370
10758 5465
87745 5949
66720 6357
76134 26466
91805 105936
31792 68220
74216 108462
60158 67410
69489 50297
74956 63776
...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 114976 lines

Test #35:

score: 32
Accepted
time: 28ms
memory: 27528kb

input:

28388 1
10509 15648
25863 14495
26973 2553
22819 7801
5054 15080
6091 12384
4727 3538
14600 14672
4481 9533
26520 23761
6729 3525
15678 8426
7628 26890
25846 26267
10186 5633
21692 25057
17882 26693
25518 13361
6875 371
27786 23632
24474 21637
1387 8015
22050 3422
8420 25752
26814 7209
11499 21112
5...

output:

1
1
1
0
1
0
0
0
0
0
0
1
0
0
0
0
1
0
1
1
1
1
0
1
1
0
0
1
1
1
0
1
0
1
0
1
1
1
0
1
0
1
1
1
0
1
1
0
1
0
1
1
0
0
0
1
0
1
0
0
1
0
0
1
1
0
1
1
1
1
0
1
1
0
1
1
1
0
0
1
1
0
1
0
0
1
1
0
1
0
0
0
0
1
0
1
1
0
0
0
1
0
1
0
0
1
1
0
1
1
0
0
0
0
1
1
0
1
1
0
0
0
0
1
1
0
0
1
1
1
1
0
1
0
0
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
...

result:

ok 28388 lines

Test #36:

score: 32
Accepted
time: 276ms
memory: 164544kb

input:

200000 1
17564 189544
118109 130056
39153 56739
138814 48828
103560 16598
174399 8469
146229 189678
173046 95721
168793 168656
21067 78280
169301 178753
63496 153947
22754 181712
34926 22205
41248 16310
81136 35768
87905 3442
89999 119217
108408 136055
153855 175444
177272 157293
174568 5857
71023 5...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #37:

score: 32
Accepted
time: 466ms
memory: 190056kb

input:

200000 1
35713 32997
199904 59024
24108 108224
75623 8060
169202 44171
166898 189166
52691 184504
91052 94474
3355 161889
76684 4006
13328 59307
83889 5391
139095 198059
194946 197068
147175 102095
68329 10784
45563 111710
123071 177610
156268 186570
149699 52604
191299 78685
68117 130476
132359 860...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #38:

score: 32
Accepted
time: 370ms
memory: 186456kb

input:

200000 1
15065 142612
651 173717
153862 68423
150849 147717
192561 152722
165359 180378
34627 59508
140908 24495
180671 177962
183330 27822
155654 53394
20596 1741
76236 52151
167441 5306
73654 149981
97720 142937
10793 84081
124721 123748
185212 150311
170407 158310
125015 73861
36456 121189
39975 ...

output:

1
0
1
1
0
0
1
0
0
0
0
0
0
0
1
0
0
1
1
0
1
1
1
1
0
0
1
0
0
0
0
1
0
1
1
1
0
1
0
1
1
0
1
1
0
1
0
1
1
1
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
1
1
1
1
1
1
1
0
1
0
1
1
1
1
0
1
1
0
1
1
0
0
1
0
0
1
1
0
0
0
0
0
0
0
0
1
0
1
0
0
1
1
0
1
1
0
1
0
0
0
1
1
1
1
0
0
0
1
0
0
0
1
0
0
0
1
1
1
1
0
1
0
0
1
1
0
0
0
1
...

result:

ok 200000 lines

Test #39:

score: 32
Accepted
time: 269ms
memory: 164944kb

input:

200000 1
86027 61282
69968 35175
136022 154753
52733 39599
97774 24158
25263 138562
112124 6412
183205 101112
112094 38819
113526 47859
137031 122132
165018 84375
76900 182974
29302 174006
34918 73123
23660 37001
141115 33742
61282 24152
150734 61282
22552 49677
106054 193519
84741 62724
6470 178907...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #40:

score: 32
Accepted
time: 313ms
memory: 168044kb

input:

200000 1
28426 75100
141794 24004
167055 168353
178427 10860
34348 190354
192106 81422
75263 134731
54229 108154
90586 122196
172392 58237
84932 15421
79435 77253
185144 24679
63387 23340
68674 72825
137398 109447
33249 46900
99738 44920
92707 125920
163133 64180
83887 123053
152655 83838
133345 953...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #41:

score: 32
Accepted
time: 275ms
memory: 166584kb

input:

200000 1
69183 39245
163717 95756
76286 79561
100403 156730
144012 28043
198819 127959
64878 40226
57715 170431
64896 172859
44376 76276
154716 52042
193460 121983
98422 173076
114307 113862
51895 51986
193923 26201
116458 6275
6786 5649
175035 64551
148902 26238
129547 45157
151907 50571
76031 8614...

output:

1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
1
1
1
1
1
1
0
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
0
0
1
1
0
1
1
0
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
0
1
0
1
0
1
1
1
0
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #42:

score: 32
Accepted
time: 295ms
memory: 166712kb

input:

200000 1
196045 146636
176533 42271
166724 196028
139244 76615
148314 148067
178418 115890
192238 183829
32675 57585
185089 143473
101515 59837
190250 186401
150802 188721
50798 191609
47863 142815
183786 28970
184954 58810
13430 196707
133210 193546
49302 49747
109810 162864
98935 133593
169908 210...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #43:

score: 0
Wrong Answer
time: 184ms
memory: 162832kb

input:

200000 1
58527 148510
90024 104304
46291 148510
148510 193006
51631 148510
148510 117266
148510 53357
166103 148510
148510 127112
148510 105363
148510 171703
56809 148510
148510 60920
164837 148510
148510 181377
67076 148510
148510 94358
8910 148510
43101 148510
148510 64867
148510 46788
148510 4249...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 17th lines differ - expected: '0', found: '1'

Subtask #3:

score: 0
Wrong Answer

Test #50:

score: 32
Accepted
time: 231ms
memory: 136116kb

input:

157976 157976
20171 157173
44732 54119
107845 121149
109200 110309
82678 108206
89140 64200
36916 128759
3966 123760
92978 105716
43700 146126
14924 3429
107721 36095
94906 78173
97162 29552
119574 39605
25145 138492
16622 99431
60281 7949
76176 136644
75716 91518
127987 110605
77999 110960
101187 5...

output:

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

result:

ok 157976 lines

Test #51:

score: 32
Accepted
time: 542ms
memory: 193388kb

input:

191205 191205
92326 99995
188142 63029
71973 50899
68069 72878
159479 103397
143191 93854
27574 146981
63427 186167
104978 177629
22355 188155
184293 15184
101908 143833
111535 144687
112209 61685
59401 128258
97717 87496
168079 130237
49319 190230
119632 98368
76193 184597
22790 136093
1080 80811
1...

output:

33816
135610
162660
131426
190598
61940
182394
60206
64348
110918
188484
7222
137922
180624
16470
93248
10468
114842
68032
166390
123722
186038
67156
83116
49318
25192
173746
73986
142500
173072
102348
118504
80854
27648
134168
50044
59926
32322
46458
177450
48524
8924
13134
77972
122644
120576
1412...

result:

ok 191205 lines

Test #52:

score: 32
Accepted
time: 44ms
memory: 31780kb

input:

31916 31916
28412 28009
2363 28056
3659 22074
23712 27943
19416 15321
14887 11666
6379 5654
30082 226
9971 14492
13981 11752
14242 10178
25107 9048
9088 6047
22323 11776
23441 9334
3950 30048
4494 25014
4971 884
25393 13071
31227 25881
16497 526
9601 6205
29829 17598
27236 31125
27869 17549
10603 95...

output:

3667
0
1133
5027
1
0
0
0
0
1
3637
5
2
2219
3691
0
2457
0
2
1
43
6677
0
5771
2
0
0
41
0
1
0
0
0
0
2013
0
0
0
0
4457
0
4763
1203
0
0
0
0
0
1957
5505
1
1945
1
0
4773
0
0
1
6637
0
0
3793
0
0
0
7359
0
6139
0
7839
0
0
31
3
2337
1
0
1111
1755
0
2513
0
3091
1
5
6505
4757
0
0
6663
7381
3041
1
1
1
0
0
6899
0
...

result:

ok 31916 lines

Test #53:

score: 32
Accepted
time: 284ms
memory: 173032kb

input:

200000 200000
8522 80636
158221 20467
137558 179244
63929 46416
190379 127249
10270 105147
121239 184388
113737 34798
56396 169095
120402 121562
6761 197808
73399 128378
119726 13343
39723 137317
13268 23687
132356 26176
102502 51172
139583 73587
58607 81019
197440 135397
159365 82319
53678 122385
1...

output:

1
5
1
3
1
1
0
0
0
1
0
1
1
1
1
3
2
2
3
1
1
1
2
1
0
3
6
2
1
3
4
3
2
1
2
2
3
1
2
1
1
6
2
1
1
2
0
1
2
3
1
1
2
3
2
1
1
0
1
2
5
1
1
2
4
7
0
0
1
5
0
8
0
1
2
1
1
0
1
1
5
0
0
3
0
6
2
2
1
1
4
0
1
2
2
3
0
2
1
1
1
0
1
0
0
4
0
2
1
1
0
1
2
1
3
2
2
2
5
1
1
0
2
2
5
3
1
1
2
1
1
8
2
3
2
1
1
1
3
1
1
1
0
3
5
2
1
0
0
2
...

result:

ok 200000 lines

Test #54:

score: 32
Accepted
time: 591ms
memory: 200084kb

input:

200000 200000
30404 3409
70531 107126
46652 168864
155049 82807
42684 194360
57108 144938
32493 124488
195042 127527
29871 96787
9762 10681
144410 79089
118939 116876
99174 154784
195005 158160
145251 149354
134536 193935
38082 51228
86551 101378
168310 57058
54208 21573
148567 60683
22941 171027
12...

output:

24449
120519
145939
82943
132849
58123
175687
1603
122977
95777
116867
185465
180903
142715
195055
176929
130585
105019
116049
29293
39467
155423
199087
94563
141289
108325
155319
162451
199235
132571
38167
4787
134333
190519
168619
24161
112719
135877
5881
189657
73303
170617
139023
137245
17979
17...

result:

ok 200000 lines

Test #55:

score: 0
Wrong Answer
time: 482ms
memory: 187932kb

input:

200000 200000
186933 177107
92441 81383
190521 1821
2186 115541
122869 138915
148511 26011
101109 53413
167961 155222
66264 61619
179636 120704
152928 138111
154784 103804
92191 54540
120375 62394
50610 56843
191955 157924
191074 86487
103991 100799
188410 33656
72771 176718
90528 132562
133333 1227...

output:

0
51163
16592
18618
71297
69141
70393
0
43198
8934
40786
2
87585
54969
41516
0
67225
46500
52637
56975
1
0
62199
98827
5218
0
11782
33784
2332
72771
84177
4
94517
3962
9056
74267
77155
51417
60137
9222
80231
81441
79993
95163
59545
97205
77935
45282
0
0
1
65857
51719
31804
2
1
3
70565
28050
0
10272
...

result:

wrong answer 2nd lines differ - expected: '1356', found: '51163'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%