QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#44274#1785. 轻重边myee100 ✓938ms48568kbC++113.8kb2022-08-14 21:02:312022-08-14 21:02:33

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-14 21:02:33]
  • 评测
  • 测评结果:100
  • 用时:938ms
  • 内存:48568kb
  • [2022-08-14 21:02:31]
  • 提交

answer

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
struct Info
{
    uint vl,vr,w;
    friend Info operator+(Info a,Info b)
    {
        if(!a.vl)return b;
        if(!b.vr)return a;
        return{a.vl,b.vr,a.w+b.w+(a.vr!=b.vl)};
    }
    Info swap(){return{vr,vl,w};}
};
struct Seg
{
    uint len;Seg*L,*R;bol tag;Info v;
    Seg(uint n):len(n),L(NULL),R(NULL),tag(false),v({0,0,0}){if(n>1)L=new Seg(n>>1),R=new Seg(n-(n>>1));}
    voi pushdown(){if(tag)L->chg(0,len>>1,v.vl),R->chg(0,len-(len>>1),v.vl),tag=false;}
    voi pushup(){v=L->v+R->v;}
    Info find(uint l,uint r)
    {
        if(l>=r)return{0,0,0};
        if(!l&&r==len)return v;
        pushdown();
        if(l<(len>>1))
            if(r<=(len>>1))return L->find(l,r);
            else return L->find(l,len>>1)+R->find(0,r-(len>>1));
        else return R->find(l-(len>>1),r-(len>>1));
    }
    voi chg(uint l,uint r,uint w)
    {
        if(l>=r)return;
        if(!l&&r==len){v={w,w,0},tag=true;return;}
        pushdown();
        if(l<(len>>1))
            if(r<=(len>>1))L->chg(l,r,w);
            else L->chg(l,len>>1,w),R->chg(0,r-(len>>1),w);
        else R->chg(l-(len>>1),r-(len>>1),w);
        pushup();
    }
}*S;
std::vector<uint>Way[100005];
uint Siz[100005],Heavy[100005],Fath[100005],Rot[100005],Dep[100005],Dfn[100005],cnt;
voi dfs1(uint p,uint f)
{
    Siz[p]=1,Fath[p]=f,Heavy[p]=-1;
    for(auto s:Way[p])if(s!=f)
    {
        Dep[s]=Dep[p]+1,dfs1(s,p),Siz[p]+=Siz[s];
        if(!~Heavy[p]||Siz[s]>Siz[Heavy[p]])Heavy[p]=s;
    }
}
voi dfs2(uint p,uint r)
{
    Rot[p]=r,Dfn[p]=cnt++;if(~Heavy[p])dfs2(Heavy[p],r);else return;
    for(auto s:Way[p])if(s!=Fath[p]&&s!=Heavy[p])dfs2(s,s);
}
uint lca(uint u,uint v) // test
{
    while(u[Rot]!=v[Rot])
    {
        if(u[Rot][Dep]<v[Rot][Dep])std::swap(u,v);
        u=u[Rot][Fath];
    }
    return u[Dep]<v[Dep]?u:v;
}
Info _get(uint y,uint o)
{
    Info ans{0,0,0};
    while(Rot[y]!=Rot[o])ans=S->find(Dfn[Rot[y]],Dfn[y]+1)+ans,y=Fath[Rot[y]];
    ans=S->find(Dfn[o],Dfn[y]+1)+ans;return ans;
}
voi _chg(uint y,uint o,uint c)
{
    while(Rot[y]!=Rot[o])S->chg(Dfn[Rot[y]],Dfn[y]+1,c),y=Fath[Rot[y]];
    S->chg(Dfn[o],Dfn[y]+1,c);
}
uint get(uint u,uint v){uint r=lca(u,v);return Dep[u]+Dep[v]-Dep[r]*2-(_get(u,r).swap()+_get(v,r)).w;}
voi chg(uint u,uint v,uint c){uint r=lca(u,v);_chg(u,r,c),_chg(v,r,c);}
voi solve()
{
    uint n,q;scanf("%u%u",&n,&q),cnt=0;
    for(uint i=0;i<n;i++)Way[i].clear();
    for(uint i=1,u,v;i<n;i++)scanf("%u%u",&u,&v),Way[--u].push_back(--v),Way[v].push_back(u);
    dfs1(0,0),dfs2(0,0);
    S=new Seg(n);
    uint w=1;for(uint i=0;i<n;i++)S->chg(Dfn[i],Dfn[i]+1,w++);
    while(q--)
    {
        uint op,u,v;scanf("%u%u%u",&op,&u,&v);
        if(op==1)chg(u-1,v-1,w++);else printf("%u\n",get(u-1,v-1));
    }
}
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
    uint t;scanf("%u",&t);while(t--)solve();
    return 0;
}

详细

Test #1:

score: 5
Accepted
time: 3ms
memory: 7572kb

input:

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

output:

2
0
0
0
0
1
0
0
2
2
1
0
1
2

result:

ok 14 lines

Test #2:

score: 5
Accepted
time: 1ms
memory: 6316kb

input:

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

output:

0
3
2
1
0
1
1
1
0
1
2
2

result:

ok 12 lines

Test #3:

score: 5
Accepted
time: 22ms
memory: 9092kb

input:

3
4691 4033
141 4537
2326 1658
1170 2567
2602 2235
4073 3976
2976 4052
814 922
551 3848
1739 3392
3646 3990
1095 4575
2939 286
2927 1846
3333 818
3095 162
3761 2541
881 2634
3436 2861
4517 401
3702 438
2894 355
4395 304
4028 3919
1660 3426
2927 374
4673 99
2724 3034
616 3218
2760 4348
4631 3839
1218...

output:

9
1
12
0
0
11
12
29
39
11
40
13
13
26
0
23
8
70
41
12
15
24
28
21
57
11
13
25
69
15
58
8
21
38
25
59
60
51
38
20
83
9
45
83
45
6
18
20
22
28
23
57
24
0
27
51
25
24
24
38
30
45
0
32
28
27
46
36
18
50
19
20
48
32
29
20
42
35
47
24
13
34
34
32
0
49
12
28
22
21
78
39
16
10
33
30
29
33
30
45
33
36
23
31
...

result:

ok 6741 lines

Test #4:

score: 5
Accepted
time: 16ms
memory: 8792kb

input:

3
3748 4382
1320 3727
1198 3101
2145 793
2375 2101
2862 2544
242 604
2744 134
2157 3398
429 3187
33 804
830 511
128 2441
2558 1603
3731 3161
1873 3697
2057 2553
394 635
1566 3413
1365 2416
3692 3338
762 3664
3474 2808
1357 914
1571 2884
2772 2389
840 1711
2275 2160
2324 2670
103 257
1317 28
2163 153...

output:

6
38
6
27
19
33
27
13
25
22
14
26
1
18
17
33
20
6
39
41
26
36
15
9
39
30
12
23
45
21
42
26
25
40
7
1
25
33
19
18
21
17
29
41
26
29
34
25
20
18
18
18
24
25
14
44
6
21
21
30
29
27
17
30
29
44
22
5
3
24
43
21
40
16
42
13
24
41
38
6
6
31
32
18
36
7
14
28
18
38
15
47
19
33
31
8
7
26
24
16
45
5
34
4
45
39...

result:

ok 6212 lines

Test #5:

score: 5
Accepted
time: 25ms
memory: 7724kb

input:

3
5000 5000
1819 180
3088 312
1963 2811
4857 4770
300 2152
4759 3872
245 4439
3874 3127
2479 1936
3765 1768
2194 2485
160 1992
1760 533
2113 2337
4701 252
2502 2391
1053 600
28 1932
4998 669
3996 2157
4481 4154
4240 4059
4421 266
4730 1363
2964 101
3238 3926
941 1276
1939 4154
784 3856
3871 3495
477...

output:

0
16
0
0
59
2
75
77
30
75
24
60
47
59
1
14
25
22
70
24
29
0
11
26
32
80
23
14
43
95
28
41
49
75
26
38
13
48
24
100
20
36
3
9
37
16
54
85
63
72
21
52
82
8
58
14
89
50
6
79
11
41
54
82
12
58
15
57
45
8
71
39
68
55
18
55
58
11
20
79
45
18
89
70
39
30
14
32
43
71
66
18
77
32
70
86
77
20
87
44
72
13
53
9...

result:

ok 7504 lines

Test #6:

score: 5
Accepted
time: 24ms
memory: 9828kb

input:

3
5000 5000
2595 2044
1369 2070
4147 3320
2661 3652
1198 2984
2636 1033
2431 3650
4461 3438
2156 2971
437 2848
1687 1625
2602 4656
2542 2423
1260 612
3556 516
4294 2516
3669 3420
274 2253
4238 1069
3642 1794
3586 252
2768 1582
4198 22
2335 155
3222 3159
2471 6
957 798
2693 4872
1874 4183
3128 374
5 ...

output:

0
56
19
21
35
31
58
43
71
9
59
5
23
37
38
10
33
28
17
100
44
21
38
4
19
33
71
2
46
49
26
10
46
23
29
38
68
53
40
59
54
46
8
60
56
22
41
55
33
72
28
38
31
79
47
53
26
45
22
45
77
39
16
25
23
79
55
15
23
82
12
11
21
29
69
46
48
27
32
39
24
19
34
85
31
26
83
32
43
71
80
17
51
80
105
68
33
26
69
40
42
4...

result:

ok 8263 lines

Test #7:

score: 5
Accepted
time: 304ms
memory: 39292kb

input:

3
80753 79382
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
49 50
50 51
51 ...

output:

0
1
0
0
0
0
0
0
0
1
1
0
1
1
1
1
1
1
0
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
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 119073 lines

Test #8:

score: 5
Accepted
time: 433ms
memory: 48568kb

input:

3
100000 100000
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
49 50
50 51
5...

output:

1
1
0
0
0
1
0
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
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 149961 lines

Test #9:

score: 5
Accepted
time: 345ms
memory: 40948kb

input:

3
85306 96255
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
49 50
50 51
51 ...

output:

0
20929
1117
39620
30865
26113
28573
16622
51710
12826
65894
7348
60055
71547
3734
21494
36153
619
29407
23212
10079
18401
30621
20023
33453
3421
3412
1863
30525
37532
7448
13231
50073
11674
11952
23503
6022
5485
30126
8058
14680
41405
17046
8090
4234
48556
48720
27505
32307
58400
58330
71649
19722
...

result:

ok 127775 lines

Test #10:

score: 5
Accepted
time: 457ms
memory: 48528kb

input:

3
100000 100000
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
49 50
50 51
5...

output:

24303
42249
4144
3055
698
32261
9589
36548
24443
53848
47026
24879
60517
60599
66694
730
67826
12460
60987
46524
56325
55782
19336
10349
24339
12330
29913
78906
30710
7266
20028
56241
35971
38209
1986
35413
5779
44484
51040
43662
48585
78430
62492
41972
2866
72696
42806
23409
54922
18465
23865
19911...

result:

ok 149908 lines

Test #11:

score: 5
Accepted
time: 643ms
memory: 40740kb

input:

3
97203 94161
44820 65179
65179 61439
61439 73263
73263 77468
77468 84098
84098 16816
16816 87458
87458 75540
75540 25930
25930 15686
15686 53399
53399 50620
50620 71205
71205 72887
72887 40025
40025 75694
75694 30817
30817 54444
54444 53761
53761 32609
32609 43392
43392 66768
66768 5020
5020 59550
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 147867 lines

Test #12:

score: 5
Accepted
time: 435ms
memory: 42384kb

input:

3
75542 80437
19963 55367
55367 4361
4361 33808
33808 18119
18119 1765
1765 6558
6558 20580
20580 74183
74183 16658
16658 4165
4165 29389
29389 70762
70762 64930
64930 11518
11518 58871
58871 40781
40781 60462
60462 38675
38675 2241
2241 12696
12696 37564
37564 33100
33100 72437
72437 45638
45638 15...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 136491 lines

Test #13:

score: 5
Accepted
time: 642ms
memory: 45500kb

input:

3
100000 100000
11698 62060
62060 5345
5345 19041
19041 6205
6205 9172
9172 22236
22236 63405
63405 75901
75901 51825
51825 75629
75629 6492
6492 36485
36485 77384
77384 54779
54779 58192
58192 75576
75576 60729
60729 68607
68607 4424
4424 19234
19234 63754
63754 95475
95475 6402
6402 57023
57023 89...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 166606 lines

Test #14:

score: 5
Accepted
time: 561ms
memory: 44852kb

input:

3
100000 100000
61704 48070
48070 82948
82948 8908
8908 98947
98947 86428
86428 82915
82915 51940
51940 83640
83640 64655
64655 37694
37694 17204
17204 16152
16152 34222
34222 63303
63303 18924
18924 16228
16228 76950
76950 37608
37608 75769
75769 7852
7852 83829
83829 57099
57099 49908
49908 16984
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 166524 lines

Test #15:

score: 5
Accepted
time: 118ms
memory: 13340kb

input:

3
16143 13827
2266 7230
7230 10028
10028 14162
14162 13128
13128 4201
4201 6762
6762 2379
2379 22
22 11312
11312 6945
6945 3012
3012 14651
14651 14057
14057 8400
8400 10591
10591 14094
14094 261
261 10274
10274 7514
7514 14695
14695 648
648 712
712 1377
1377 9916
9916 11801
11801 6939
6939 14820
148...

output:

16
11
2
17
17
31
24
10
51
43
32
7
16
0
2
43
6
29
22
5
56
22
22
48
0
8
12
21
31
28
49
20
8
28
25
13
25
38
36
20
4
6
37
1
16
25
1
26
4
13
29
17
46
27
18
44
15
27
52
23
15
55
46
15
10
19
52
34
1
24
30
35
10
43
34
15
23
16
13
15
39
35
3
25
5
16
60
23
22
30
34
21
40
6
52
13
15
14
33
31
25
16
11
11
1
19
3...

result:

ok 26693 lines

Test #16:

score: 5
Accepted
time: 98ms
memory: 14728kb

input:

3
20000 20000
19539 12265
12265 17534
17534 3954
3954 5924
5924 6333
6333 2247
2247 2198
2198 18380
18380 6704
6704 6466
6466 4334
4334 680
680 8984
8984 9068
9068 9292
9292 19855
19855 18513
18513 15340
15340 6641
6641 14302
14302 15898
15898 16810
16810 8968
8968 1871
1871 11736
11736 16886
16886 ...

output:

11
40
0
16
52
35
24
13
36
32
22
22
27
0
61
27
40
2
5
64
0
38
9
10
5
4
56
6
10
20
24
12
22
50
38
3
36
27
38
53
0
51
51
10
31
28
46
34
51
34
4
36
41
23
10
4
50
29
11
24
46
11
10
22
34
43
13
23
30
44
1
6
41
30
3
18
17
11
6
7
50
21
20
22
31
65
24
50
4
26
2
1
8
14
2
5
46
3
43
4
14
0
7
6
31
15
14
42
50
57...

result:

ok 33125 lines

Test #17:

score: 5
Accepted
time: 617ms
memory: 33268kb

input:

3
76695 67966
56425 31646
31646 59459
59459 37624
37624 57860
57860 65929
65929 4666
4666 51436
51436 9891
9891 12967
12967 13631
13631 43482
43482 28423
28423 43744
43744 29260
29260 74681
74681 5829
5829 54747
54747 42982
42982 8731
8731 34518
34518 64770
64770 39919
39919 32001
32001 66142
66142 ...

output:

1
18
50
21
6
22
7
26
8
8
44
42
17
13
15
17
7
0
20
39
10
37
10
26
40
43
3
11
10
17
24
4
8
22
23
43
41
24
14
5
22
32
35
5
14
8
26
7
12
28
48
58
32
5
7
33
1
15
33
8
22
16
27
17
32
44
27
44
1
8
56
51
49
9
51
2
35
42
13
19
9
59
3
26
45
32
44
54
24
4
8
56
53
17
19
39
8
39
18
14
11
39
11
1
15
2
40
13
58
34...

result:

ok 132245 lines

Test #18:

score: 5
Accepted
time: 638ms
memory: 35344kb

input:

3
88368 77279
30630 86625
86625 20534
20534 65929
65929 77511
77511 40182
40182 63591
63591 29184
29184 66661
66661 55108
55108 87420
87420 71371
71371 7396
7396 76428
76428 29032
29032 12480
12480 46843
46843 53896
53896 26905
26905 20769
20769 83597
83597 77572
77572 9339
9339 64901
64901 80992
80...

output:

13
28
17
16
25
28
24
52
14
28
39
31
6
5
11
19
6
21
12
46
1
4
20
9
28
5
29
10
21
29
0
7
12
27
27
41
52
41
41
3
52
25
4
37
33
3
3
37
18
37
19
3
42
48
53
14
14
3
12
10
16
1
37
27
38
11
7
19
8
24
18
9
5
41
41
25
56
39
1
64
2
5
36
34
27
26
55
19
45
9
16
25
10
19
11
39
8
20
37
34
18
6
50
4
10
15
55
22
7
8...

result:

ok 136450 lines

Test #19:

score: 5
Accepted
time: 703ms
memory: 44484kb

input:

3
100000 100000
78746 26777
26777 80762
80762 78780
78780 90725
90725 325
325 59763
59763 89996
89996 69707
69707 666
666 12511
12511 19026
19026 90674
90674 21918
21918 18930
18930 47467
47467 36299
36299 97733
97733 15682
15682 69920
69920 32575
32575 82734
82734 31361
31361 99748
99748 51727
5172...

output:

1
3
46
3
12
65
18
14
34
21
2
45
4
10
37
0
27
28
40
24
17
21
55
34
32
45
23
28
51
9
41
15
45
65
7
11
50
56
7
33
10
36
15
48
15
15
32
1
58
7
34
38
53
2
6
8
4
0
17
27
28
47
29
30
14
10
32
46
3
34
8
27
8
9
23
45
11
15
40
6
66
0
22
5
4
21
10
25
6
47
51
17
13
6
35
9
9
53
2
21
40
13
5
0
33
33
12
50
20
34
3...

result:

ok 166718 lines

Test #20:

score: 5
Accepted
time: 938ms
memory: 45384kb

input:

3
100000 100000
55651 6780
6780 23348
23348 7670
7670 58893
58893 79852
79852 61518
61518 20795
20795 62023
62023 93634
93634 37598
37598 84149
84149 19931
19931 98776
98776 31452
31452 3000
3000 92083
92083 69668
69668 52244
52244 41889
41889 96128
96128 8508
8508 32863
32863 12469
12469 20195
2019...

output:

9
12
20
10
34
24
45
4
13
25
13
15
3
6
18
30
8
31
25
55
22
13
44
21
17
8
8
29
6
32
25
32
4
8
30
62
6
29
20
3
7
14
6
35
29
39
31
6
30
5
0
19
11
36
40
52
27
22
39
35
45
42
39
23
29
13
38
29
13
22
9
30
17
32
54
14
38
14
8
39
45
53
37
27
36
6
6
24
19
26
8
23
10
28
29
23
8
25
6
18
25
34
48
9
1
13
15
11
9
...

result:

ok 166789 lines

Extra Test:

score: 0
Extra Test Passed