QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372105#6396. Puzzle: KusabiQingyyxAC ✓58ms120144kbC++174.6kb2024-03-30 21:41:322024-03-30 21:41:32

Judging History

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

  • [2024-03-30 21:41:32]
  • 评测
  • 测评结果:AC
  • 用时:58ms
  • 内存:120144kb
  • [2024-03-30 21:41:32]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int MAXN = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
inline int read() { int s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(int* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
int n, m, q;
struct EG {
    int to, nxt;
}e[MAXN << 1];
int head[MAXN], etot;
inline void add(int u, int v) {
    e[etot] = EG{ v, head[u] };
    head[u] = etot++;
}
void clear(int n = MAXN - 1) { memset(head + 1, -1, sizeof(int) * n); etot = 0; }
int fa[MAXN], dep[MAXN];
vector<pii>ans;
bool com[MAXN];
struct FFF {
    // int com;
    map<int, int>mp;
    struct CMP { bool operator()(int a, int b) { return dep[a] < dep[b]; } };
    priority_queue<int, vector<int>, CMP> q1, q2;  // 短 长
    bool del() {
        int s1 = q1.size(), s2 = q2.size();
        if (!s1 && !s2)return true;
        if (abs(s1 - s2) > 1)return false;
        vector<int>v1, v2;
        while (!q1.empty())v1.push_back(q1.top()), q1.pop();
        while (!q2.empty())v2.push_back(q2.top()), q2.pop();
        int rst = -1;
        if (s2 > s1)reverse(all(v1)), reverse(all(v2));
        for (int i = 0, j = 0; i < s1 && j < s2; ++i, ++j) {
            if (dep[v1[i]] >= dep[v2[j]]) {
                if (s1 == s2)return false;
                if (rst != -1)return false;
                if (s1 > s2)rst = v1[i], --j;
                else rst = v2[j], --i;
            } else {
                ans.push_back({ v1[i], v2[j] });
            }
        }
        if (s1 > s2) {
            if (rst != -1)q1.push(rst);
            else q1.push(v1[s1 - 1]);
        } else if (s1 < s2) {
            if (rst != -1)q2.push(rst);
            else q2.push(v2[s2 - 1]);
        }
        return true;
    }
}f[MAXN];
bool bfs() {
    vector<int>path;
    queue<int>q;
    q.push(1);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        if (com[u])f[u].mp[dep[u]] = u;
        path.push_back(u);
        for (int i = head[u]; ~i; i = e[i].nxt) {
            q.push(e[i].to);
            dep[e[i].to] = dep[u] + 1;
        }
    }
    reverse(all(path));
    for (auto u : path) {
        if (!f[u].del())return !printf("NO\n");
        if (f[u].q1.size() > 1 || f[u].q2.size() > 1 || f[u].mp.size() > 1)return !printf("NO\n");
        if (f[u].mp.size() && (f[u].q1.size() || f[u].q2.size()))return !printf("NO\n");
        for (auto& [d, v] : f[u].mp) {
            if (f[fa[u]].mp.count(d)) {
                ans.push_back({ v, f[fa[u]].mp[d] });
                f[fa[u]].mp.erase(d);
            } else f[fa[u]].mp[d] = v;
        }
        if (!f[u].q1.empty())f[fa[u]].q1.push(f[u].q1.top());
        if (!f[u].q2.empty())f[fa[u]].q2.push(f[u].q2.top());
    }
    if (f[0].mp.size() || f[0].q1.size() || f[0].q2.size())return !printf("NO\n");
    return true;
}
void solve() {
    string s;
    cin >> n;
    clear(n);
    for (int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v >> s;
        add(v, u); fa[u] = v;
        if (s == "Tong")com[u] = 1;
        else if (s == "Duan")f[u].q1.push(u);
        else if (s == "Chang")f[u].q2.push(u);
    }
    if (bfs()) {
        printf("YES\n");
        for (auto& [x, y] : ans)
            printf("%d %d\n", x, y);
    }
}
signed main(signed argc, char const* argv[]) {
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    //=============================================================
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int TxT = 1;
    while (TxT--)
        solve();
    //=============================================================
#ifdef LOCAL
    end :
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 113208kb

input:

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

output:

YES
5 4
6 8

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 11ms
memory: 113248kb

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: 113132kb

input:

2
2 1 Tong

output:

NO

result:

ok Correct.

Test #4:

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

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
85183 80940
68238 77477
55487 92481
80321 90768
26757 61425
85031 74064
55495 42921
93032 85218
61332 79084
70206 54289
38376 81194
87608 50270
87995 69185
84503 96568
80329 87650
80462 99841
56280 91879
93342 71681
68256 49562
91053 83902
45401 92379
47304 51481
37299 48856
55343 68883
15089 86...

result:

ok Correct.

Test #5:

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

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
77529 85007
94990 85287
80143 91387
49983 37273
57819 89837
41068 74899
46653 94573
70043 70086
65251 76734
88167 87863
34335 87688
32074 33907
92239 86640
36497 88248
77530 82691
36957 61348
86273 85912
86444 78874
70825 71093
37315 57414
56018 90566
61875 98528
85846 91743
78637 85275
60916 83...

result:

ok Correct.

Test #6:

score: 0
Accepted
time: 51ms
memory: 120000kb

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
97601 97840
98570 99927
99872 99923
97037 90904
93657 98674
97278 99292
96917 97153
99109 98918
89534 91919
91562 93849
88445 99416
88743 93859
97734 98027
95886 95961
98352 99213
97464 98937
82392 87179
98351 91429
93746 98530
90982 93238
94748 97229
88190 98532
99481 97966
87701 97134
94116 74...

result:

ok Correct.

Test #7:

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

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
91954 92861
91434 93335
98059 93899
92444 97461
94537 95439
92799 94126
87516 89614
93526 97921
88597 92766
89001 87396
87784 98040
88134 94698
95134 96777
91610 99421
93157 89825
85711 86295
92889 97958
83443 90842
84005 84896
85808 91724
98810 95932
89502 99875
87098 87268
86158 91531
95750 96...

result:

ok Correct.

Test #8:

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

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
97710 99449
99881 99187
98203 98482
99169 99472
99695 99926
99486 99372
99924 99495
96519 96571
94328 94569
99179 99882
94118 94920
97267 98303
97034 98388
95628 98506
98256 99032
99105 99734
97831 98060
94210 95502
96199 97800
98563 99149
98661 98644
99312 99392
99191 99511
98119 98548
95965 96...

result:

ok Correct.

Test #9:

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

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
99002 99871
99455 99935
98568 98703
98775 99014
99051 99295
98728 98613
98330 98794
98596 98666
98537 98949
98269 98494
99308 99531
99464 99767
97740 97660
98981 99431
96790 97318
99570 99947
96958 97178
99288 98907
99555 99682
99413 99718
99690 99797
98180 99419
98556 98832
98632 99216
99684 99...

result:

ok Correct.

Test #10:

score: 0
Accepted
time: 23ms
memory: 115508kb

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
95727 95009
95032 95826
92731 93287
92589 93509
94115 94816
91889 92036
91071 99808
91183 98582
93463 93894
90894 95056
88023 88429
90013 93053
89615 91559
90450 91513
87571 88651
87267 88524
87179 89...

result:

ok Correct.

Test #11:

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

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
93050 78891
68751 36153
83117 63196
98139 46536
24098 80198
67516 35563
89988 29431
96843 46167
24783 88171
73598 20243
11139 55234
62595 58735
29042 73062
84974 81859
95755 47297
61622 32136
65243 99142
50504 79869
43307 35112
34406 34242
23870 14906
79207 28768
70173 18177
95211 28068
70765 32...

result:

ok Correct.

Test #12:

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

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
66302 15102
40113 37177
67876 67735
98880 70745
72747 13573
65914 49326
93527 68801
65868 25142
92842 49908
64953 23941
24514 99253
92736 35889
75236 39951
76061 30071
93473 92397
96031 60513
68877 60365
75049 50966
82782 63396
39240 10319
44038 39040
62932 60661
91847 49882
82514 36066
86525 48...

result:

ok Correct.

Test #13:

score: 0
Accepted
time: 53ms
memory: 119228kb

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
27596 14063
38849 34955
41588 40110
54430 50491
61983 55203
69085 63894
72642 72241
75216 73765
88086 85544
95158 88697
18595 10786
24025 21493
30164 25178
40282 30800
52476 50699
76452 59910
86389 79238
96792 91441
46043 34098
49151 47433
57549 56601
65754 59254
87547 66989
96382 94062
21999 14...

result:

ok Correct.

Test #14:

score: 0
Accepted
time: 41ms
memory: 116300kb

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
62964 51260
73003 64799
98672 87232
38059 31245
58383 47626
82570 78385
91105 84269
90700 67893
97507 95599
96567 51711
97467 90521
76866 67504
97376 48982
73151 61972
95255 90926
88130 66342
71350 40816
95951 92365
77306 65926
2480 84425
3281 2969
90471 99880
3614 97387
3958 3715
4406 3981
4989...

result:

ok Correct.

Test #15:

score: 0
Accepted
time: 31ms
memory: 116276kb

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
32530 24271
38484 37384
38753 38738
39709 39458
46496 43803
49313 49018
53261 51853
54934 54125
59449 56321
62015 60751
81679 70717
97806 89831
26046 18859
30675 28373
34688 33247
43694 39921
46485 44356
55259 54712
57761 57280
58424 58304
61172 61007
71317 68370
73977 73029
88437 76662
97190 93...

result:

ok Correct.

Test #16:

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

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
72014 60220
95022 80211
94029 93125
85950 59250
89854 77242
61755 56243
86382 80147
91748 86818
89771 87876
336 95747
408 97446
452 98648
464 377
481 97158
569 564
577 570
614 92488
630 624
722 664
774 745
781 775
793 783
824 95750
831 805
839 837
865 843
880 866
915 895
921 919
948 933
1007 954...

result:

ok Correct.

Test #17:

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

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: 43ms
memory: 118164kb

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: 17ms
memory: 116324kb

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: 45ms
memory: 117524kb

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: 40ms
memory: 118160kb

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: 32ms
memory: 118308kb

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: 28ms
memory: 116848kb

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: 32ms
memory: 116384kb

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: 25ms
memory: 115740kb

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: 38ms
memory: 116408kb

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: 42ms
memory: 120072kb

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: 40ms
memory: 118388kb

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: 31ms
memory: 119560kb

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: 35ms
memory: 120144kb

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: 40ms
memory: 119372kb

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
99957 99959
99958 99960
99954 99956
99944 99945
99947 99952
99948 99949
99937 99942
99938 99939
99932 99933
99935 99936
99928 99931
99929 9...

result:

ok Correct.

Test #32:

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

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
19368 16519
20002 19370
23276 22372
23892 23623
25678 25053
26238 26012
27730 27219
28074 27745
28666 28638
29163 28834
29412 29193
29474 29427
29948 29584
30054 30011
30343 30281
30822 30739
30991 30976
31161 31022
32177 32140
32851 32415
32956 32863
33012 32972
33116 33083
33345 33338
33556 33...

result:

ok Correct.

Test #33:

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

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
73972 59669
39373 29538
45676 43825
39643 66636
73300 68486
71114 15616
61662 92094
54079 56374
51777 58779
89214 92038
51729 79715
52001 91931
54089 59992
26175 65054
59652 65249
36554 49740
46097 50472
28787 37619
76994 60608
48367 70144
39620 87207
63988 82288
11598 31389
76777 89143
90025 79...

result:

ok Correct.

Test #34:

score: 0
Accepted
time: 56ms
memory: 119488kb

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
71886 58313
88337 81302
17095 70030
76609 57838
46082 61987
49044 58426
44963 30645
53023 69693
83035 89381
75689 87654
69877 83186
85407 85168
38920 79463
36841 74431
37289 74808
50554 86286
83917 90294
21741 55098
26076 38474
58922 83059
46947 37646
73731 57783
75306 83806
83436 71907
72392 80...

result:

ok Correct.

Test #35:

score: 0
Accepted
time: 50ms
memory: 118084kb

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
71063 90448
47226 70985
53817 54731
60928 71130
52065 60775
61249 50496
53816 92806
61834 78644
62538 52856
88965 46399
56708 39731
34925 71949
76915 91538
61559 72307
61678 77871
56059 78776
92577 72630
50165 43085
50118 54218
65662 48076
93305 58948
92566 54406
57283 71777
25314 68919
43914 74...

result:

ok Correct.

Test #36:

score: 0
Accepted
time: 58ms
memory: 119900kb

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
66577 81930
77584 83933
80055 65297
31276 29443
63072 92455
67573 71866
90058 81017
72371 92912
63337 70317
61159 70245
52559 94399
90825 63382
72465 85114
43588 59449
75636 85452
58621 64850
37597 26528
48922 56643
23195 51157
28814 88704
72587 71956
62845 98093
86719 94855
42364 64539
56961 92...

result:

ok Correct.

Test #37:

score: 0
Accepted
time: 16ms
memory: 114632kb

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
23516 21994
15103 16618
8235 16434
9591 22264
12691 21246
8616 19880
7451 6480
19343 22041
21772 22971
21287 24144
12423 9392
13423 18950
8597 8276
22122 22868
13258 24765
9420 16589
24114 20519
14003 22750
4662 12386
18730 23940
22949 19691
16708 20031
11390 23804
20964 19209
20929 24705
20868 ...

result:

ok Correct.

Test #38:

score: 0
Accepted
time: 51ms
memory: 119440kb

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
47101 87399
51058 37196
60086 87646
39053 64188
60799 84986
27729 91714
57410 86184
31825 89760
92590 73100
24943 84050
78293 88324
23925 35872
22558 27833
84125 16888
48734 67687
86392 67113
75253 89379
61040 83797
79762 64759
74594 84043
32439 90045
35795 84021
71668 88437
12330 22901
25486 29...

result:

ok Correct.

Test #39:

score: 0
Accepted
time: 56ms
memory: 118724kb

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
65354 60215
50583 64748
82652 76854
83879 99612
47764 55350
44945 99125
51254 70421
30991 24793
93981 29314
54560 59804
64777 73704
79685 89280
89166 73131
84338 74169
34349 61141
49210 40026
62762 67573
30362 80616
51451 80150
34986 63900
88309 91487
78819 99160
88748 69692
55300 66253
90406 75...

result:

ok Correct.

Test #40:

score: 0
Accepted
time: 56ms
memory: 119344kb

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
78156 78204
36397 51967
78133 82427
88498 64018
73958 79070
38876 57455
53774 24511
34717 43404
48285 58713
36514 37948
68802 72670
81149 87893
22228 85556
43245 61304
58325 81901
79174 88072
76311 89317
83101 57811
60999 83169
87899 78228
88652 81696
71803 89571
34101 61523
34710 76502
44985 65...

result:

ok Correct.

Test #41:

score: 0
Accepted
time: 54ms
memory: 118144kb

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
84470 85877
84813 56796
38530 51632
42797 88602
40261 38876
71776 54401
60185 69746
70827 81856
60101 84668
83494 62691
86069 92180
43585 44601
81751 18333
90588 90933
72672 70859
64621 69372
70527 90432
35538 67445
92165 78561
29027 25529
50471 41341
64876 87364
47113 46964
92148 80338
42123 78...

result:

ok Correct.

Test #42:

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

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
61403 84069
84102 92293
64473 88097
55424 81431
51261 72143
79826 86058
52423 92072
47929 63157
52677 50738
67233 82708
89940 91160
57962 92066
79443 68904
79893 77530
51909 57177
59297 60350
62145 85916
35934 66794
36823 50820
55573 86852
68102 69228
68267 61759
44978 66952
39762 75739
86019 87...

result:

ok Correct.

Test #43:

score: 0
Accepted
time: 19ms
memory: 113068kb

input:

1

output:

YES

result:

ok Correct.