QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104256#6396. Puzzle: KusabiMelacau#AC ✓48ms18716kbC++172.9kb2023-05-09 20:39:512023-05-09 20:39:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-09 20:39:54]
  • 评测
  • 测评结果:AC
  • 用时:48ms
  • 内存:18716kb
  • [2023-05-09 20:39:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

typedef enum {NONE, SAME, SHORT, LONG} NodeType;
int n, f[N], d[N];
NodeType psh[N], cur[N];

vector<int> rem[N][4];
vector<pair<int, int>> ans;

void gg() {
    cout << "NO\n";
    exit(0);
} 

int solve(int u) {
    psh[u] = NONE;
    int res = 0;
    for (int i = SAME; i <= LONG; ++i) 
        sort(rem[u][i].begin(), rem[u][i].end(), [&](int x, int y){return d[x] < d[y];});
    {
        for (int i = 0, j, k; i < rem[u][SAME].size(); i = j) {
            for (j = i; j < rem[u][SAME].size() && d[rem[u][SAME][i]] == d[rem[u][SAME][j]]; ++j);
            for (k = i; k + 2 <= j; k += 2) ans.emplace_back(rem[u][SAME][k], rem[u][SAME][k + 1]);
            if (k < j) {
                if (res) gg();
                psh[u] = SAME;
                res = rem[u][SAME][k];
            }
        }
    }
    if (rem[u][SHORT].size() < rem[u][LONG].size()) {
        int diff = rem[u][LONG].size() - rem[u][SHORT].size();
        if (diff > 1 || res) gg();
        psh[u] = LONG;
        int j = 0;
        for (int i = 0; i < rem[u][SHORT].size(); ++i) {
            while (d[rem[u][LONG][j]] <= d[rem[u][SHORT][i]]) {
                if (res) gg();
                res = rem[u][LONG][j++];
            }
            ans.emplace_back(rem[u][SHORT][i], rem[u][LONG][j++]);
        }
        if (j < rem[u][LONG].size())
            res = rem[u][LONG][j];
    }
    else if (rem[u][SHORT].size() > rem[u][LONG].size()) {
        int diff = rem[u][SHORT].size() - rem[u][LONG].size();
        if (diff > 1 || res) gg();
        psh[u] = SHORT;
        int j = int(rem[u][SHORT].size()) - 1;
        for (int i = int(rem[u][LONG].size()) - 1; i >= 0; --i) {
            while (d[rem[u][SHORT][j]] >= d[rem[u][LONG][i]]) {
                if (res) gg();
                res = rem[u][SHORT][j--];
            }
            ans.emplace_back(rem[u][LONG][i], rem[u][SHORT][j--]);
        }
        if (j >= 0) res = rem[u][SHORT][j];
    }
    else {
        for (int i = 0; i < rem[u][SHORT].size(); ++i)
            if (d[rem[u][SHORT][i]] >= d[rem[u][LONG][i]]) gg();
            else ans.emplace_back(rem[u][SHORT][i], rem[u][LONG][i]);
    }   
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for (int i = 2, x; i <= n; ++i) {
        cin >> x; cin >> f[x];
        d[x] = d[f[x]] + 1;
        static string s; cin >> s;
        if (s == "Tong"s) cur[x] = SAME;
        else if (s == "Duan"s) cur[x] = SHORT;
        else if (s == "Chang"s) cur[x] = LONG;
        else cur[x] = NONE;
    }
    for (int i = n; i; --i) {
        if (cur[i] != NONE) rem[i][cur[i]].emplace_back(i);
        int p = solve(i);
        if (p) {
            if (i == 1) gg();
            else rem[f[i]][psh[i]].emplace_back(p);
        }
    }
    cout << "YES\n";
    for (auto [x, y]: ans)
        cout << x << ' ' << y << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 12812kb

input:

8
2 1 -
3 1 -
4 2 Tong
5 2 Tong
6 3 Duan
7 3 -
8 7 Chang

output:

YES
6 8
5 4

result:

ok Correct.

Test #2:

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

input:

10
2 1 Duan
3 2 Duan
4 2 -
5 4 Chang
6 2 Chang
7 1 Duan
8 6 Tong
9 6 Tong
10 3 Chang

output:

YES
9 8
3 10
2 6
7 5

result:

ok Correct.

Test #3:

score: 0
Accepted
time: 7ms
memory: 12724kb

input:

2
2 1 Tong

output:

NO

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 39ms
memory: 17788kb

input:

100000
2 1 Duan
3 1 Duan
4 3 -
5 4 Duan
6 3 -
7 4 Duan
8 4 -
9 8 -
10 7 Duan
11 9 -
12 7 Duan
13 7 Duan
14 8 Duan
15 13 -
16 10 Duan
17 11 Duan
18 12 -
19 1 Duan
20 5 Duan
21 4 Duan
22 14 Duan
23 16 -
24 22 Duan
25 16 Duan
26 13 -
27 13 -
28 17 -
29 5 Duan
30 22 -
31 23 -
32 9 Duan
33 5 -
34 30 Duan...

output:

YES
99188 99893
98791 98950
98563 99758
98299 98540
98287 99817
98253 99347
98179 98789
98000 99611
97798 98580
97712 98524
97659 99795
97544 98151
97488 98357
97469 99308
97428 98460
97313 99596
97130 97733
97014 99609
96874 99598
96860 98948
96780 99468
96654 97621
96616 97426
96541 99500
96366 97...

result:

ok Correct.

Test #5:

score: 0
Accepted
time: 24ms
memory: 15080kb

input:

100000
2 1 -
3 2 -
4 3 -
5 4 -
6 4 -
7 6 -
8 7 -
9 5 -
10 9 -
11 10 -
12 6 -
13 12 -
14 11 -
15 9 -
16 14 -
17 16 -
18 10 -
19 15 -
20 13 -
21 20 -
22 17 -
23 22 -
24 22 Duan
25 11 -
26 12 -
27 20 -
28 18 -
29 28 -
30 16 -
31 28 -
32 30 -
33 31 -
34 28 -
35 34 -
36 35 -
37 22 -
38 34 -
39 38 -
40 35...

output:

YES
98544 98903
99744 97809
95253 96073
95222 95666
95187 96756
94042 98686
94000 95407
93557 99938
92888 97078
92767 97706
92253 93318
91867 99751
89309 95022
87280 97379
86612 86868
86322 99527
85608 88203
98912 96472
84953 89195
84533 87174
84189 98944
84015 94789
83849 88017
83839 99600
87719 84...

result:

ok Correct.

Test #6:

score: 0
Accepted
time: 48ms
memory: 18716kb

input:

100000
2 1 -
3 2 -
4 3 Duan
5 4 Chang
6 5 Duan
7 6 Chang
8 7 Duan
9 8 Chang
10 9 Duan
11 10 Chang
12 11 Duan
13 12 Chang
14 12 Duan
15 14 Chang
16 15 Tong
17 15 Tong
18 17 Duan
19 18 Duan
20 19 Chang
21 18 Duan
22 21 Duan
23 18 Chang
24 21 -
25 24 Duan
26 25 Chang
27 26 Duan
28 27 Chang
29 26 Duan
3...

output:

YES
99901 99952
99872 99923
99855 99865
99819 99820
99761 99842
99711 99947
99675 99869
99660 99767
99649 99726
99613 99673
99603 99870
99563 99625
99529 99882
99525 99662
99521 99719
99471 99831
99443 99871
99442 99774
99426 99709
99421 99988
99420 99785
99417 99620
99399 99771
99398 99933
99381 99...

result:

ok Correct.

Test #7:

score: 0
Accepted
time: 34ms
memory: 16396kb

input:

100000
2 1 -
3 2 -
4 3 -
5 4 -
6 5 -
7 6 -
8 7 -
9 8 -
10 9 Duan
11 10 -
12 11 Chang
13 12 Duan
14 13 Chang
15 14 -
16 15 -
17 16 Duan
18 17 Chang
19 17 -
20 19 -
21 20 -
22 21 -
23 22 -
24 23 -
25 24 -
26 25 Duan
27 26 -
28 27 Duan
29 28 -
30 29 Chang
31 28 -
32 31 Chang
33 32 -
34 32 -
35 34 -
36 ...

output:

YES
99887 99898
99741 99801
99435 99763
99338 99737
99317 99985
99278 99836
99241 99390
99169 99385
99089 99486
99269 99162
98900 99170
98832 99502
99114 99402
98801 99873
98770 99941
98701 99479
98683 99292
98622 99690
98540 98722
98538 99425
98531 99313
98528 98726
99648 99504
98519 98563
98475 98...

result:

ok Correct.

Test #8:

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

input:

100000
2 1 -
3 2 -
4 3 -
5 4 -
6 5 Duan
7 6 -
8 7 -
9 8 -
10 9 Chang
11 10 -
12 11 Duan
13 12 Chang
14 13 -
15 14 Duan
16 15 Chang
17 16 -
18 17 -
19 18 Duan
20 19 -
21 20 -
22 21 -
23 22 Chang
24 23 -
25 24 Duan
26 25 -
27 26 Chang
28 27 -
29 28 -
30 29 -
31 30 Duan
32 31 -
33 32 -
34 33 -
35 34 -
...

output:

YES
99825 99910
99773 99914
99748 99904
99746 99941
99707 99879
99682 99719
99681 99721
99695 99926
99639 99940
99876 99770
99591 99983
99838 99820
99574 99982
99527 99930
99525 99912
99981 99566
99517 99980
99497 99731
99487 99866
99462 99986
99537 99954
99423 99705
99419 99989
99410 99436
99924 99...

result:

ok Correct.

Test #9:

score: 0
Accepted
time: 27ms
memory: 17368kb

input:

100000
2 1 -
3 2 -
4 3 -
5 4 -
6 5 Duan
7 6 -
8 7 -
9 8 Chang
10 9 -
11 10 Duan
12 11 -
13 12 Chang
14 13 Duan
15 14 -
16 15 Chang
17 16 -
18 17 Duan
19 18 -
20 19 Chang
21 20 Duan
22 21 Chang
23 22 -
24 23 Duan
25 24 Chang
26 25 Duan
27 26 -
28 27 -
29 28 Chang
30 29 Duan
31 30 Chang
32 31 -
33 32 ...

output:

YES
99980 99950
99910 99944
99895 99972
99892 99912
99869 99958
99868 99915
99867 99873
99835 99840
99832 99893
99821 99916
99823 99969
99811 99842
99807 99880
99806 99918
99805 99854
99800 99977
99787 99853
99780 99956
99906 99798
99863 99894
99825 99959
99758 99924
99737 99858
99734 99813
99731 99...

result:

ok Correct.

Test #10:

score: 0
Accepted
time: 22ms
memory: 14660kb

input:

100000
2 1 -
3 2 -
4 3 -
5 4 -
6 5 -
7 6 -
8 7 -
9 8 -
10 9 -
11 10 -
12 11 -
13 12 -
14 13 -
15 14 -
16 15 -
17 16 -
18 17 -
19 18 -
20 19 -
21 20 -
22 21 -
23 22 -
24 23 -
25 24 -
26 25 -
27 26 -
28 27 -
29 28 -
30 29 -
31 30 -
32 31 -
33 32 -
34 33 -
35 34 -
36 35 -
37 36 -
38 37 -
39 38 -
40 39 ...

output:

YES
98805 99672
98016 98458
98030 98307
96964 97211
98406 99646
96353 99283
96874 97770
95149 95528
95032 95826
94115 94816
95727 95009
92731 93287
92589 93509
93463 93894
91889 92036
90894 95056
91071 99808
91183 98582
90013 93053
89615 91559
90450 91513
89379 90095
88023 88429
87571 88651
87179 89...

result:

ok Correct.

Test #11:

score: 0
Accepted
time: 20ms
memory: 15644kb

input:

100000
2 1 -
3 1 -
4 2 -
5 1 -
6 1 -
7 2 Duan
8 4 -
9 1 -
10 1 -
11 2 -
12 2 -
13 2 -
14 6 -
15 1 -
16 6 -
17 1 -
18 5 -
19 1 -
20 1 -
21 2 -
22 8 -
23 6 -
24 1 -
25 4 Duan
26 1 -
27 10 -
28 1 -
29 8 -
30 5 -
31 7 -
32 2 -
33 3 -
34 12 -
35 3 -
36 1 -
37 12 -
38 8 -
39 8 -
40 1 -
41 4 -
42 16 -
43 8...

output:

YES
75386 98984
74599 88504
71533 88752
68244 84445
67816 85297
65243 99142
62830 96320
60044 86906
98674 92744
59135 95922
59081 98317
58950 78115
58842 83453
58789 89951
58465 81407
58379 86050
57732 90119
57492 79482
57364 93815
57329 98132
96761 92286
55435 89266
55417 81154
55236 94389
54787 91...

result:

ok Correct.

Test #12:

score: 0
Accepted
time: 18ms
memory: 14812kb

input:

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

output:

YES
34081 96138
32638 92038
29917 98752
85530 72048
26741 83793
25594 83390
24746 51571
24514 99253
24053 82889
23435 95659
22917 74140
88551 85624
22420 83536
77529 72975
19261 94752
18687 82174
18226 97204
18213 70452
52816 44737
17672 55957
17603 44191
17412 54382
92630 75040
17061 73788
16726 68...

result:

ok Correct.

Test #13:

score: 0
Accepted
time: 27ms
memory: 17380kb

input:

100000
2 1 Duan
3 1 Duan
4 1 Duan
5 1 Duan
6 1 Duan
7 1 -
8 1 Duan
9 1 Duan
10 1 -
11 1 Duan
12 1 -
13 1 Duan
14 1 Duan
15 1 Duan
16 1 Duan
17 1 Duan
18 2 -
19 1 Duan
20 1 Duan
21 2 -
22 2 Duan
23 1 Duan
24 1 Duan
25 1 Duan
26 1 Duan
27 2 Duan
28 1 Duan
29 2 Duan
30 1 Duan
31 2 Duan
32 1 -
33 1 Duan...

output:

YES
24185 95290
23069 84377
22292 99368
19592 89445
19496 72374
19154 96974
18706 87380
18590 99651
18568 95831
18138 78334
17976 85482
17932 75813
17923 95215
17812 99987
17623 99744
17365 68399
17200 94399
17055 99708
17013 75421
16800 96421
16705 99937
16662 75231
16409 80879
16402 92710
16346 80...

result:

ok Correct.

Test #14:

score: 0
Accepted
time: 18ms
memory: 15316kb

input:

100000
2 1 -
3 1 -
4 1 -
5 1 -
6 1 -
7 1 -
8 1 -
9 1 -
10 1 -
11 1 -
12 1 -
13 1 Duan
14 1 -
15 1 -
16 1 -
17 1 -
18 1 -
19 1 -
20 1 -
21 1 -
22 1 -
23 1 -
24 1 -
25 1 -
26 1 -
27 1 -
28 1 -
29 1 Duan
30 1 -
31 1 -
32 2 Duan
33 1 -
34 1 -
35 1 Duan
36 1 -
37 1 -
38 1 -
39 1 -
40 1 -
41 1 -
42 1 -
43...

output:

YES
7802 96840
5707 95443
5612 99364
5258 82470
4984 67953
4918 92074
4906 96828
4566 94271
4253 92851
95951 92365
4177 85612
4093 75547
4059 99977
4054 89009
3937 76769
3913 95320
3906 82876
82940 63945
3614 97387
3609 92591
97300 81898
3515 92246
3490 56765
78522 75453
3427 66057
3382 85599
3348 6...

result:

ok Correct.

Test #15:

score: 0
Accepted
time: 18ms
memory: 14812kb

input:

100000
2 1 Duan
3 1 -
4 1 -
5 1 Duan
6 1 -
7 1 -
8 1 -
9 1 -
10 1 -
11 1 -
12 1 -
13 1 -
14 1 -
15 1 -
16 1 -
17 1 -
18 1 -
19 1 -
20 1 -
21 1 -
22 1 -
23 1 -
24 1 -
25 1 -
26 1 -
27 1 -
28 1 -
29 1 -
30 1 -
31 1 -
32 1 -
33 1 Duan
34 1 -
35 1 -
36 1 -
37 1 -
38 1 -
39 1 -
40 1 -
41 1 -
42 1 -
43 1 ...

output:

YES
2267 96706
1484 93600
1309 79300
1269 78139
90885 89109
1226 65492
1204 87298
89056 62078
80577 54647
96099 87384
94915 51801
82132 68475
98136 87425
1091 64953
91261 85731
1057 92548
1041 49779
98921 91147
91941 88328
95875 90647
91502 88522
82759 79496
87202 71064
96551 66113
945 78623
94704 8...

result:

ok Correct.

Test #16:

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

input:

100000
2 1 Duan
3 1 Duan
4 1 -
5 1 Duan
6 1 -
7 1 Duan
8 1 Duan
9 1 Duan
10 1 Duan
11 1 -
12 1 -
13 1 -
14 1 Duan
15 1 Duan
16 1 Duan
17 1 -
18 1 Duan
19 1 Duan
20 1 Duan
21 1 -
22 1 -
23 1 Duan
24 1 Duan
25 1 Duan
26 1 -
27 1 -
28 1 Duan
29 1 Duan
30 1 -
31 1 Duan
32 1 Duan
33 1 -
34 1 Duan
35 1 -
...

output:

YES
824 95750
705 83464
622 95111
614 92488
598 96448
575 99954
92518 91152
99688 93861
531 92449
528 71582
524 66385
518 91774
96388 95679
502 95051
495 68161
491 92051
79514 71560
486 91617
481 97158
466 92920
456 94768
86414 82066
71375 69375
455 94412
452 98648
451 96222
92101 86461
99900 97252
...

result:

ok Correct.

Test #17:

score: 0
Accepted
time: 28ms
memory: 15828kb

input:

100000
2 1 -
3 1 -
4 2 -
5 2 -
6 2 Duan
7 3 -
8 1 -
9 1 -
10 6 -
11 3 -
12 2 -
13 7 -
14 1 -
15 9 -
16 11 -
17 13 -
18 9 -
19 16 -
20 19 -
21 8 -
22 5 -
23 14 -
24 21 -
25 21 -
26 16 -
27 5 -
28 5 -
29 19 -
30 8 -
31 24 -
32 30 -
33 12 Duan
34 9 -
35 12 Duan
36 6 -
37 15 -
38 26 -
39 29 -
40 13 -
41...

output:

NO

result:

ok Correct.

Test #18:

score: 0
Accepted
time: 32ms
memory: 17320kb

input:

100000
2 1 Duan
3 2 Duan
4 3 -
5 3 Duan
6 4 -
7 4 Duan
8 3 Duan
9 2 -
10 4 Duan
11 8 Duan
12 6 -
13 3 Duan
14 6 Duan
15 7 Duan
16 6 Duan
17 14 Tong
18 7 -
19 16 Duan
20 14 Duan
21 12 Duan
22 20 Duan
23 14 Duan
24 19 -
25 2 Duan
26 22 -
27 24 Duan
28 8 Duan
29 4 Duan
30 23 Duan
31 24 Duan
32 23 Duan
...

output:

NO

result:

ok Correct.

Test #19:

score: 0
Accepted
time: 14ms
memory: 15100kb

input:

100000
2 1 -
3 2 -
4 3 -
5 4 -
6 5 -
7 4 -
8 7 -
9 8 -
10 9 -
11 10 Duan
12 9 -
13 12 -
14 12 -
15 10 -
16 8 -
17 13 -
18 10 -
19 14 -
20 13 -
21 19 -
22 19 Duan
23 11 -
24 23 Duan
25 23 -
26 5 -
27 22 -
28 22 Duan
29 17 -
30 29 -
31 29 -
32 17 -
33 27 -
34 33 Duan
35 31 -
36 24 -
37 34 -
38 37 -
39...

output:

NO

result:

ok Correct.

Test #20:

score: 0
Accepted
time: 30ms
memory: 15976kb

input:

100000
2 1 Duan
3 2 Chang
4 3 -
5 4 -
6 5 -
7 6 Duan
8 7 -
9 8 Chang
10 9 Duan
11 10 Chang
12 11 -
13 12 Duan
14 13 Chang
15 13 -
16 15 -
17 15 -
18 15 Duan
19 18 -
20 19 Duan
21 19 Chang
22 20 -
23 22 -
24 21 Duan
25 23 -
26 22 -
27 25 Chang
28 26 -
29 28 Duan
30 24 Chang
31 28 -
32 23 -
33 28 -
34...

output:

NO

result:

ok Correct.

Test #21:

score: 0
Accepted
time: 21ms
memory: 15344kb

input:

100000
2 1 Duan
3 2 Chang
4 3 -
5 4 -
6 5 Duan
7 6 -
8 7 -
9 8 Chang
10 9 Duan
11 10 Chang
12 11 Duan
13 12 Chang
14 12 -
15 14 -
16 15 Duan
17 16 Chang
18 17 -
19 17 Duan
20 19 -
21 19 Chang
22 21 -
23 21 Duan
24 23 Duan
25 24 Chang
26 24 Chang
27 24 Duan
28 27 -
29 28 Chang
30 28 Duan
31 30 -
32 3...

output:

NO

result:

ok Correct.

Test #22:

score: 0
Accepted
time: 22ms
memory: 16932kb

input:

100000
2 1 Duan
3 2 Chang
4 3 Duan
5 4 -
6 5 Chang
7 6 -
8 7 Duan
9 8 -
10 9 Chang
11 10 Duan
12 11 Chang
13 12 -
14 13 Duan
15 14 -
16 15 Chang
17 16 -
18 17 Duan
19 18 -
20 19 -
21 20 -
22 21 Chang
23 22 -
24 23 Duan
25 24 Chang
26 25 -
27 26 Duan
28 27 -
29 28 Chang
30 28 Duan
31 30 -
32 31 Chang...

output:

NO

result:

ok Correct.

Test #23:

score: 0
Accepted
time: 26ms
memory: 15036kb

input:

100000
2 1 Duan
3 2 -
4 3 -
5 4 -
6 5 -
7 6 -
8 7 -
9 8 -
10 9 -
11 10 -
12 11 Chang
13 12 Duan
14 13 -
15 14 -
16 15 Chang
17 16 Duan
18 17 Chang
19 18 -
20 19 -
21 20 -
22 21 -
23 22 -
24 23 -
25 24 -
26 25 Duan
27 26 -
28 27 -
29 28 -
30 29 -
31 30 -
32 31 -
33 32 -
34 33 Chang
35 34 -
36 35 -
37...

output:

NO

result:

ok Correct.

Test #24:

score: 0
Accepted
time: 18ms
memory: 14368kb

input:

100000
2 1 -
3 2 -
4 3 -
5 4 -
6 5 Duan
7 6 -
8 7 Chang
9 8 -
10 9 -
11 10 -
12 11 -
13 12 -
14 13 Duan
15 14 -
16 15 Chang
17 16 -
18 17 -
19 18 -
20 19 Duan
21 20 -
22 21 -
23 22 -
24 23 Chang
25 24 -
26 25 Duan
27 26 Chang
28 27 Duan
29 28 -
30 29 -
31 30 -
32 31 Chang
33 32 Duan
34 33 -
35 34 -
...

output:

NO

result:

ok Correct.

Test #25:

score: 0
Accepted
time: 21ms
memory: 15256kb

input:

100000
2 1 Duan
3 1 -
4 1 -
5 1 -
6 3 -
7 2 -
8 2 -
9 4 -
10 1 -
11 2 -
12 3 Duan
13 2 -
14 4 -
15 3 -
16 3 -
17 2 -
18 2 -
19 1 -
20 7 Duan
21 1 -
22 15 -
23 6 -
24 1 -
25 8 -
26 11 -
27 5 -
28 16 -
29 17 -
30 16 -
31 3 -
32 7 -
33 3 Duan
34 7 Duan
35 3 -
36 8 -
37 6 -
38 16 -
39 3 -
40 3 -
41 11 -...

output:

NO

result:

ok Correct.

Test #26:

score: 0
Accepted
time: 21ms
memory: 15368kb

input:

100000
2 1 -
3 1 -
4 1 -
5 1 -
6 1 -
7 1 Duan
8 1 -
9 1 -
10 1 -
11 3 -
12 2 -
13 1 -
14 1 -
15 1 -
16 2 -
17 1 Duan
18 3 -
19 1 -
20 1 Duan
21 8 -
22 2 -
23 3 -
24 3 Duan
25 1 -
26 1 -
27 1 -
28 1 -
29 4 -
30 1 -
31 3 -
32 3 -
33 3 -
34 2 -
35 1 -
36 1 Duan
37 1 -
38 3 -
39 2 -
40 4 -
41 2 Duan
42 ...

output:

NO

result:

ok Correct.

Test #27:

score: 0
Accepted
time: 33ms
memory: 18124kb

input:

100000
2 1 Duan
3 1 Duan
4 1 Duan
5 1 Duan
6 1 Duan
7 1 Duan
8 1 Duan
9 1 Duan
10 1 Duan
11 1 Duan
12 1 Duan
13 1 Duan
14 2 Duan
15 1 Duan
16 1 Duan
17 1 Duan
18 2 Duan
19 1 Duan
20 1 -
21 1 Duan
22 1 Duan
23 1 Duan
24 1 Duan
25 1 Duan
26 1 Duan
27 2 Duan
28 1 Duan
29 1 Duan
30 1 -
31 1 Duan
32 1 Du...

output:

NO

result:

ok Correct.

Test #28:

score: 0
Accepted
time: 24ms
memory: 16792kb

input:

100000
2 1 -
3 1 Duan
4 1 -
5 1 -
6 1 -
7 1 Duan
8 1 -
9 1 Duan
10 1 -
11 1 Duan
12 1 Duan
13 1 Duan
14 1 Duan
15 1 Duan
16 1 -
17 1 Duan
18 1 Duan
19 1 Duan
20 1 Duan
21 1 -
22 1 -
23 1 Duan
24 1 -
25 1 Duan
26 1 Duan
27 1 Duan
28 1 Duan
29 1 Duan
30 1 Duan
31 1 Duan
32 1 -
33 1 -
34 1 Duan
35 1 Du...

output:

NO

result:

ok Correct.

Test #29:

score: 0
Accepted
time: 28ms
memory: 17432kb

input:

100000
2 1 Duan
3 1 Duan
4 1 Duan
5 1 Duan
6 1 Duan
7 1 Duan
8 1 -
9 1 Duan
10 1 Duan
11 1 Duan
12 1 -
13 1 Duan
14 1 Duan
15 1 Duan
16 1 Duan
17 1 Duan
18 1 Duan
19 1 Duan
20 1 -
21 1 -
22 1 Duan
23 1 -
24 1 Duan
25 1 Duan
26 1 Duan
27 1 Duan
28 1 Duan
29 1 Duan
30 1 Duan
31 1 Duan
32 1 Duan
33 1 -...

output:

NO

result:

ok Correct.

Test #30:

score: 0
Accepted
time: 27ms
memory: 17920kb

input:

100000
2 1 Duan
3 1 -
4 1 Duan
5 1 Duan
6 1 Duan
7 1 Duan
8 1 Duan
9 1 Duan
10 1 Duan
11 1 Duan
12 1 Duan
13 1 Duan
14 1 Duan
15 1 Duan
16 1 Duan
17 1 Duan
18 1 Duan
19 1 -
20 1 Duan
21 1 Duan
22 1 Duan
23 1 Duan
24 1 Duan
25 1 Duan
26 1 Duan
27 1 Duan
28 1 -
29 1 Duan
30 1 Duan
31 1 Duan
32 1 -
33 ...

output:

NO

result:

ok Correct.

Test #31:

score: 0
Accepted
time: 27ms
memory: 18008kb

input:

100000
2 1 Duan
3 2 -
4 3 Chang
5 4 -
6 5 Duan
7 6 Chang
8 7 -
9 8 -
10 9 Duan
11 10 Chang
12 11 Duan
13 12 Chang
14 13 Duan
15 14 Chang
16 15 -
17 16 -
18 17 -
19 18 Duan
20 19 -
21 20 -
22 21 Chang
23 22 Duan
24 23 Chang
25 24 -
26 25 Duan
27 26 Chang
28 27 Duan
29 28 -
30 29 Chang
31 30 Duan
32 3...

output:

YES
99999 100000
99993 99994
99989 99992
99987 99988
99985 99986
99981 99983
99975 99976
99972 99974
99969 99970
99966 99971
99964 99965
99963 99967
99961 99962
99958 99960
99957 99959
99954 99956
99948 99949
99947 99952
99944 99945
99938 99939
99937 99942
99935 99936
99932 99933
99929 99930
99928 9...

result:

ok Correct.

Test #32:

score: 0
Accepted
time: 29ms
memory: 15056kb

input:

100000
2 1 Duan
3 1 -
4 1 -
5 1 -
6 1 -
7 1 -
8 1 -
9 1 -
10 1 -
11 1 -
12 1 Tong
13 1 -
14 1 -
15 1 -
16 1 Tong
17 1 -
18 1 -
19 1 -
20 1 -
21 1 -
22 1 Tong
23 1 -
24 1 -
25 1 -
26 1 -
27 1 -
28 1 -
29 1 -
30 1 -
31 1 -
32 1 -
33 1 -
34 1 -
35 1 -
36 1 -
37 1 -
38 1 Tong
39 1 -
40 1 -
41 1 -
42 1 -...

output:

YES
92627 90226
98157 80552
99736 96463
94233 92271
89806 89512
86996 86460
86134 85511
67953 66335
71357 81710
80845 79593
77025 74512
73891 73888
72862 81856
69427 65770
64372 60624
56615 55714
48609 88314
97391 95440
93512 92584
92085 91747
89757 89327
99860 87691
85698 85374
85318 83893
82419 82...

result:

ok Correct.

Test #33:

score: 0
Accepted
time: 27ms
memory: 15976kb

input:

93284
2 1 -
3 1 Duan
4 2 -
5 4 -
6 2 -
7 4 Duan
8 1 -
9 4 -
10 4 Duan
11 6 -
12 7 -
13 6 -
14 1 Duan
15 4 -
16 9 -
17 12 -
18 15 -
19 6 Duan
20 1 -
21 15 -
22 2 -
23 5 Duan
24 7 -
25 22 -
26 13 -
27 12 -
28 6 -
29 27 Duan
30 7 Duan
31 9 -
32 14 -
33 3 -
34 21 -
35 18 -
36 35 -
37 7 -
38 17 Duan
39 2...

output:

YES
91869 91939
90624 91617
90519 91713
89268 92453
89181 92080
89154 92476
92278 91986
88404 89367
88302 91980
87452 91481
87331 89450
87154 88372
86910 90303
86708 92548
86372 88766
85767 88464
85608 92793
85479 88351
85192 92689
85088 87370
85042 86176
84811 87745
84563 87099
84342 87439
84285 91...

result:

ok Correct.

Test #34:

score: 0
Accepted
time: 39ms
memory: 18260kb

input:

92284
2 1 Duan
3 2 -
4 3 Duan
5 2 Duan
6 3 -
7 4 Duan
8 6 Duan
9 4 Duan
10 6 Duan
11 4 Duan
12 8 Chang
13 1 Duan
14 5 Duan
15 5 -
16 15 Duan
17 15 Duan
18 13 Chang
19 12 Duan
20 4 -
21 1 Duan
22 17 Duan
23 2 Duan
24 14 Duan
25 17 Duan
26 22 Duan
27 4 -
28 26 Duan
29 9 Duan
30 15 Duan
31 3 Duan
32 7 ...

output:

YES
91543 91986
91078 91373
90938 91500
90831 91639
90827 91238
90668 91221
90658 91847
90639 91492
90529 91259
90465 91713
90346 90523
89983 90868
89923 90124
89918 90531
89917 91825
89900 91087
89856 90001
89815 91565
89756 91579
89744 91726
89701 89781
89654 90985
89570 92081
89561 90328
89471 91...

result:

ok Correct.

Test #35:

score: 0
Accepted
time: 27ms
memory: 16952kb

input:

93444
2 1 -
3 1 Duan
4 1 Duan
5 2 -
6 4 -
7 3 -
8 6 Duan
9 6 Duan
10 9 -
11 2 -
12 1 -
13 11 -
14 5 -
15 14 Duan
16 11 -
17 16 -
18 4 -
19 7 Duan
20 15 -
21 17 -
22 21 -
23 20 -
24 23 Duan
25 7 -
26 14 Duan
27 18 -
28 13 Duan
29 2 Duan
30 19 Duan
31 5 -
32 7 Duan
33 23 Duan
34 17 Duan
35 2 Duan
36 2...

output:

YES
92922 93242
92472 93224
92396 93244
91744 92279
91546 92740
91453 92260
91416 92405
91351 91620
91273 91284
90951 92145
90812 92844
90764 92048
90703 92909
90407 92180
90358 92734
90320 90766
90317 90887
90302 92424
90208 93359
90068 91671
89905 91173
89894 90396
90849 90128
89794 90340
89490 90...

result:

ok Correct.

Test #36:

score: 0
Accepted
time: 43ms
memory: 18572kb

input:

98244
2 1 Duan
3 1 Duan
4 3 Duan
5 4 Duan
6 4 Duan
7 4 Duan
8 5 Duan
9 8 Duan
10 5 Duan
11 9 Duan
12 3 Duan
13 11 Tong
14 5 Duan
15 5 Duan
16 12 Duan
17 2 Duan
18 3 Duan
19 4 Duan
20 2 Duan
21 6 Duan
22 21 Duan
23 1 -
24 15 -
25 20 Duan
26 8 Duan
27 13 Duan
28 12 Duan
29 22 Duan
30 24 Duan
31 21 Dua...

output:

YES
97624 98183
97345 97816
97262 97885
97145 97945
97140 98027
96983 97385
96884 97505
96774 97233
96773 97390
96585 98096
96564 97297
96414 97499
96325 96826
96237 97052
96213 97801
96202 96346
96074 97504
95822 97048
95805 96013
95791 97976
95740 95902
95724 96968
95568 97684
95491 96777
95480 96...

result:

ok Correct.

Test #37:

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

input:

25284
2 1 Duan
3 2 -
4 3 -
5 3 Duan
6 2 Duan
7 3 Duan
8 1 Duan
9 5 -
10 4 -
11 5 Duan
12 4 Duan
13 1 Duan
14 4 -
15 10 Duan
16 8 -
17 13 -
18 15 -
19 12 -
20 16 Duan
21 6 Duan
22 2 Duan
23 19 -
24 12 -
25 2 -
26 19 Duan
27 5 -
28 4 -
29 9 -
30 12 Duan
31 7 Duan
32 31 -
33 21 -
34 24 Duan
35 28 Duan
...

output:

YES
25074 25109
24777 25111
24695 25017
24571 25215
24432 24916
24294 24904
24189 25193
24138 24388
24065 24628
24028 25226
23851 24841
23799 24589
23738 24043
23730 24672
23714 24045
23671 24641
23661 24348
23576 24400
23565 24105
23558 24951
23478 24392
23467 23936
23456 24091
23448 24998
23431 23...

result:

ok Correct.

Test #38:

score: 0
Accepted
time: 44ms
memory: 18040kb

input:

93246
2 1 Duan
3 2 Duan
4 3 Duan
5 1 -
6 4 Tong
7 4 Duan
8 4 Duan
9 8 -
10 6 Duan
11 2 Duan
12 1 Duan
13 11 Duan
14 8 Duan
15 1 Duan
16 8 Duan
17 10 Duan
18 3 Duan
19 1 Duan
20 18 Duan
21 10 Duan
22 14 Duan
23 11 Duan
24 19 Duan
25 21 Duan
26 17 Duan
27 24 Duan
28 24 Duan
29 17 Tong
30 23 Duan
31 17...

output:

YES
93190 93191
92822 92972
92750 92914
92629 92708
92569 92781
92006 92847
91801 91984
91527 92766
91525 92391
91431 91819
91337 91706
91254 93240
91246 91761
91107 91199
91097 91753
91083 91242
91014 92358
90890 92884
90887 91589
90823 91118
90804 91173
90754 90797
90677 92524
90612 90825
90529 92...

result:

ok Correct.

Test #39:

score: 0
Accepted
time: 35ms
memory: 17456kb

input:

99837
2 1 -
3 1 -
4 3 Duan
5 2 Duan
6 5 Duan
7 3 Duan
8 5 -
9 6 Duan
10 4 -
11 4 -
12 6 Duan
13 8 -
14 7 -
15 10 Duan
16 11 Duan
17 8 Duan
18 6 -
19 13 Duan
20 16 Duan
21 20 -
22 19 Chang
23 4 Duan
24 13 Duan
25 21 -
26 17 Duan
27 7 Duan
28 8 -
29 3 -
30 18 -
31 21 Duan
32 27 Duan
33 21 Duan
34 17 -...

output:

YES
99382 99803
98936 99179
98875 99565
98846 99201
98796 99462
98570 99023
98477 99816
98371 99404
98142 98301
98057 99177
99251 98851
97946 98639
97742 98587
97554 98617
97550 98795
97498 97667
97464 97888
97340 99252
97289 98809
97275 98761
97239 97961
97214 97619
96932 97096
96811 97204
96731 97...

result:

ok Correct.

Test #40:

score: 0
Accepted
time: 45ms
memory: 18232kb

input:

91248
2 1 Duan
3 1 Duan
4 1 Duan
5 2 Duan
6 3 Duan
7 3 Chang
8 2 Duan
9 1 Duan
10 7 Duan
11 10 Duan
12 4 Duan
13 2 Duan
14 11 Duan
15 6 Duan
16 8 Duan
17 7 Duan
18 2 Duan
19 15 Duan
20 4 Duan
21 7 Duan
22 6 Duan
23 6 Duan
24 20 Duan
25 13 Duan
26 22 Duan
27 5 Duan
28 19 Duan
29 14 Duan
30 12 -
31 8 ...

output:

YES
90690 91156
90546 91022
90529 91072
90458 91100
90451 90935
90199 90894
90118 91121
90017 90349
89833 90799
89786 90290
89703 90230
89680 91005
89659 91219
89656 91030
89652 90905
89643 90239
89593 90624
89537 90454
89454 89459
89388 89522
89220 90089
89159 90739
89094 90928
89043 90879
88908 89...

result:

ok Correct.

Test #41:

score: 0
Accepted
time: 28ms
memory: 16760kb

input:

93538
2 1 -
3 2 -
4 2 -
5 3 Duan
6 4 -
7 4 -
8 2 -
9 1 -
10 7 -
11 4 Duan
12 8 -
13 9 -
14 1 Duan
15 7 Duan
16 3 -
17 5 -
18 14 Duan
19 5 -
20 7 -
21 15 Duan
22 9 -
23 8 -
24 16 Duan
25 5 Duan
26 6 Duan
27 10 -
28 7 -
29 21 Duan
30 1 -
31 18 -
32 13 -
33 6 -
34 28 -
35 16 Duan
36 32 Duan
37 22 -
38 ...

output:

YES
92655 93253
92469 93452
92264 92776
92236 92804
92080 92124
91729 93209
91547 93102
91505 92681
91492 92346
91361 93327
91016 93105
90984 91732
90889 92187
90852 92379
90808 92111
90753 93408
90710 91642
90588 90933
90540 91163
90533 92246
90526 93196
90374 93034
90359 90705
90312 90890
90246 91...

result:

ok Correct.

Test #42:

score: 0
Accepted
time: 36ms
memory: 17176kb

input:

92384
2 1 Duan
3 2 -
4 3 Duan
5 3 Duan
6 3 -
7 2 Duan
8 1 -
9 7 Duan
10 5 Chang
11 4 -
12 3 Duan
13 7 -
14 9 Duan
15 14 Chang
16 3 Duan
17 6 Duan
18 10 Duan
19 17 Duan
20 10 -
21 2 Duan
22 10 -
23 5 Duan
24 18 -
25 11 -
26 13 Duan
27 12 Duan
28 1 -
29 18 Duan
30 28 Duan
31 28 -
32 16 -
33 27 Duan
34...

output:

YES
91307 91485
91232 91297
91219 91550
91145 92242
90821 91787
90510 91677
90369 91466
90354 91528
90350 90759
90338 90961
90314 91501
90258 91704
90122 91010
90073 90250
89940 91160
89923 90296
89858 90027
89769 90542
89726 91443
89594 92301
89582 89884
89519 91158
89502 91600
89163 92377
89116 90...

result:

ok Correct.

Test #43:

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

input:

1

output:

YES

result:

ok Correct.