Codeforces Round 153 (Div. 1)
B
Playing with Permutations
Codeforces
1800
原题
← AC →
翻译中…

Little Petya likes permutations a lot. Recently his mom has presented him permutation $*q*_{1}, *q*_{2}, ..., *q*_{*n*}$ of length $*n*$.

翻译中…

A permutation $*a*$ of length $*n*$ is a sequence of integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ $(1 ≤ *a*_{*i*} ≤ *n*)$, all integers there are distinct.

翻译中…

There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length $*n*$. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules:

翻译中…
  • Before the beginning of the game Petya writes permutation $1, 2, ..., *n*$ on the blackboard. After that Petya makes exactly $*k*$ moves, which are described below.
  • During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2.
  • Let's assume that the board contains permutation $*p*_{1}, *p*_{2}, ..., *p*_{*n*}$ at the given moment. Then Petya removes the written permutation $*p*$ from the board and writes another one instead: $*p*_{*q*_{1}}, *p*_{*q*_{2}}, ..., *p*_{*q*_{*n*}}$. In other words, Petya applies permutation $*q*$ (which he has got from his mother) to permutation $*p*$.
    • All actions are similar to point 1, except that Petya writes permutation $*t*$ on the board, such that: $*t*_{*q*_{*i*}} = *p*_{*i*}$ for all $*i*$ from 1 to $*n*$. In other words, Petya applies a permutation that is inverse to $*q*$ to permutation $*p*$.
翻译中…

We know that after the $*k*$-th move the board contained Masha's permutation $*s*_{1}, *s*_{2}, ..., *s*_{*n*}$. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the $*k*$-th move. Note that the game has exactly $*k*$ moves, that is, throughout the game the coin was tossed exactly $*k*$ times.

翻译中…

Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*k*$ ($1 ≤ *n*, *k* ≤ 100$). The second line contains $*n*$ space-separated integers $*q*_{1}, *q*_{2}, ..., *q*_{*n*}$ ($1 ≤ *q*_{*i*} ≤ *n*$) — the permutation that Petya's got as a present. The third line contains Masha's permutation $*s*$, in the similar format.

翻译中…

It is guaranteed that the given sequences $*q*$ and $*s*$ are correct permutations.

翻译中…

Output

翻译中…

If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes).

翻译中…

Note

翻译中…

In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before $*k*$ moves were performed.

翻译中…

In the second sample the described situation is possible, in case if after we toss a coin, we get tails.

翻译中…

In the third sample the possible coin tossing sequence is: heads-tails-tails.

翻译中…

In the fourth sample the possible coin tossing sequence is: heads-heads.

翻译中…

样例

Input #1
4 1
2 3 4 1
1 2 3 4
Output #1
NO
InputCopy OutputCopy
Input #2
4 1
4 3 1 2
3 4 2 1
Output #2
YES
InputCopy OutputCopy
Input #3
4 3
4 3 1 2
3 4 2 1
Output #3
YES
InputCopy OutputCopy
Input #4
4 2
4 3 1 2
2 1 4 3
Output #4
YES
InputCopy OutputCopy
Input #5
4 1
4 3 1 2
2 1 4 3
Output #5
NO
InputCopy OutputCopy
题目信息
题号
251B
时间限制
2 s
内存限制
256 MB
标签
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。