UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212861#3819. A13270460609100591ms3624kbC++534b2024-10-20 14:58:372024-10-20 18:48:33

answer

#include <cstdio>
#include <cmath>
using namespace std;
const int maxn = 4e5 + 5;
int n;
int nxt[maxn], dist[maxn];
int main() {
    scanf("%d", &n);
    int head, lst;
    scanf("%d", &head);
    lst = head;
    for (int i = 2; i <= n; lst = nxt[lst], i++) scanf("%d", nxt + lst);
    dist[head] = 1;
    for (int i = head; i; i = nxt[i]) dist[nxt[i]] = dist[i] + 1;
    bool ans = true;
    for (int i = 2; i <= n && ans; i++) ans &= abs(dist[i] - dist[i - 1]) <= 2;
    printf(ans ? "Yes" : "No");
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

95
47 46 70 45 79 90 24 23 89 5 34 76 81 87 53 28 60 55 12 35 1 17 2 20 33 93 71 22 40 56 27 44 10 7...

output:

No

result:

ok "No"

Test #2:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
1 6 2 4 5 3

output:

No

result:

ok "No"

Test #3:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
5 3 2 6 4 1

output:

No

result:

ok "No"

Test #4:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

6
1 4 5 2 6 3

output:

No

result:

ok "No"

Test #5:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
1 3 5 2 4 6

output:

No

result:

ok "No"

Test #6:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

6
3 1 6 2 4 5

output:

No

result:

ok "No"

Test #7:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
6 3 5 2 1 4

output:

No

result:

ok "No"

Test #8:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
1 2 5 6 3 4

output:

No

result:

ok "No"

Test #9:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
5 6 4 1 3 2

output:

Yes

result:

ok "Yes"

Test #10:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

6
5 1 4 3 2 6

output:

No

result:

ok "No"

Test #11:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

6
1 2 5 4 6 3

output:

No

result:

ok "No"

Test #12:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

98
46 50 82 72 96 30 28 69 35 29 16 84 95 9 47 68 3 4 74 91 53 64 98 62 66 20 54 33 86 27 65 58 41 4...

output:

No

result:

ok "No"

Test #13:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
5 3 6 4 2 1

output:

No

result:

ok "No"

Test #14:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

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

output:

Yes

result:

ok "Yes"

Test #15:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

97
23 24 22 25 21 26 20 27 19 28 18 29 17 30 16 31 15 32 14 33 13 34 12 35 11 36 10 37 9 38 8 39 7 4...

output:

Yes

result:

ok "Yes"

Test #16:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

97
81 82 80 83 79 84 78 85 77 86 76 87 75 88 74 89 73 90 72 91 71 92 70 93 69 94 68 95 67 96 66 97 6...

output:

Yes

result:

ok "Yes"

Test #17:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

99
84 83 85 82 86 81 87 80 88 79 89 78 90 77 91 76 92 75 93 74 94 73 95 72 96 71 97 70 98 69 99 68 6...

output:

Yes

result:

ok "Yes"

Test #18:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

91
29 30 28 31 27 32 26 33 25 34 24 35 23 36 22 37 21 38 20 39 19 40 18 41 17 42 16 43 15 44 14 45 1...

output:

Yes

result:

ok "Yes"

Test #19:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
2 3 1 4 5 6

output:

Yes

result:

ok "Yes"

Test #20:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
1 3 2 4 6 5

output:

Yes

result:

ok "Yes"

Test #21:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

6
1 5 6 2 4 3

output:

No

result:

ok "No"

Test #22:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

6
4 1 6 2 3 5

output:

No

result:

ok "No"

Test #23:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

6
3 2 4 6 5 1

output:

No

result:

ok "No"

Test #24:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

6
1 5 2 3 6 4

output:

No

result:

ok "No"

Test #25:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

6
5 6 3 4 2 1

output:

No

result:

ok "No"

Test #26:

score: 2
Accepted
time: 0ms
memory: 508kb

input:

2
2 1

output:

Yes

result:

ok "Yes"

Test #27:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

3
2 3 1

output:

Yes

result:

ok "Yes"

Test #28:

score: 2
Accepted
time: 0ms
memory: 504kb

input:

4
2 3 4 1

output:

No

result:

ok "No"

Test #29:

score: 2
Accepted
time: 39ms
memory: 3620kb

input:

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

output:

No

result:

ok "No"

Test #30:

score: 2
Accepted
time: 25ms
memory: 3620kb

input:

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

output:

No

result:

ok "No"

Test #31:

score: 2
Accepted
time: 42ms
memory: 3620kb

input:

399997
361233 361232 361234 361231 361235 361230 361236 361229 361237 361228 361238 361227 361239 36...

output:

Yes

result:

ok "Yes"

Test #32:

score: 2
Accepted
time: 89ms
memory: 3620kb

input:

399992
145795 277226 204608 159687 359376 160924 308780 295747 164870 352092 210204 134571 225860 24...

output:

No

result:

ok "No"

Test #33:

score: 2
Accepted
time: 67ms
memory: 3624kb

input:

399999
306696 306695 306697 306694 306698 306693 306699 306692 306700 306691 306701 306690 306702 30...

output:

Yes

result:

ok "Yes"

Test #34:

score: 2
Accepted
time: 70ms
memory: 3624kb

input:

399992
205762 205763 205761 205764 205760 205765 205759 205766 205758 205767 205757 205768 205756 20...

output:

Yes

result:

ok "Yes"

Test #35:

score: 2
Accepted
time: 38ms
memory: 3620kb

input:

399993
114546 114547 114545 114548 114544 114549 114543 114550 114542 114551 114541 114552 114540 11...

output:

Yes

result:

ok "Yes"

Test #36:

score: 2
Accepted
time: 35ms
memory: 3616kb

input:

399998
157 156 158 155 159 154 160 153 161 152 162 151 163 150 164 149 165 148 166 147 167 146 168 1...

output:

Yes

result:

ok "Yes"

Test #37:

score: 2
Accepted
time: 52ms
memory: 3620kb

input:

399993
59311 171360 52550 358944 248171 11362 248634 315497 378137 328115 242460 353314 228235 39105...

output:

No

result:

ok "No"

Test #38:

score: 2
Accepted
time: 47ms
memory: 3616kb

input:

400000
324248 148340 96118 1146 158654 266246 40598 398288 384392 177432 296798 361271 305285 210690...

output:

No

result:

ok "No"

Test #39:

score: 2
Accepted
time: 44ms
memory: 3620kb

input:

399993
68365 241952 31787 223072 343586 177853 315 272862 146209 326237 380439 12864 330776 22368 24...

output:

No

result:

ok "No"

Test #40:

score: 2
Accepted
time: 43ms
memory: 3620kb

input:

399992
252560 373234 101549 141853 282097 371781 130967 337346 304216 242521 15942 56917 229090 1777...

output:

No

result:

ok "No"

Extra Test:

score: 0
Extra Test Passed