CF251B.Playing with Permutations

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little Petya likes permutations a lot. Recently his mom has presented him permutation q1,q2,...,qnq_{1},q_{2},...,q_{n} of length nn .

A permutation aa of length nn is a sequence of integers a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=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 nn . 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,...,n1,2,...,n on the blackboard. After that Petya makes exactly kk 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.
    1. Let's assume that the board contains permutation p1,p2,...,pnp_{1},p_{2},...,p_{n} at the given moment. Then Petya removes the written permutation pp from the board and writes another one instead: pq1,pq2,...,pqnp_{q1},p_{q2},...,p_{qn} . In other words, Petya applies permutation qq (which he has got from his mother) to permutation pp .
    2. All actions are similar to point 1, except that Petya writes permutation tt on the board, such that: tqi=pit_{qi}=p_{i} for all ii from 1 to nn . In other words, Petya applies a permutation that is inverse to qq to permutation pp .

We know that after the kk -th move the board contained Masha's permutation s1,s2,...,sns_{1},s_{2},...,s_{n} . Besides, we know that throughout the game process Masha's permutation never occurred on the board before the kk -th move. Note that the game has exactly kk moves, that is, throughout the game the coin was tossed exactly kk 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.

输入格式

The first line contains two integers nn and kk ( 1<=n,k<=1001<=n,k<=100 ). The second line contains nn space-separated integers q1,q2,...,qnq_{1},q_{2},...,q_{n} ( 1<=qi<=n1<=q_{i}<=n ) — the permutation that Petya's got as a present. The third line contains Masha's permutation ss , in the similar format.

It is guaranteed that the given sequences qq and ss are correct permutations.

输出格式

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

输入输出样例

  • 输入#1

    4 1
    2 3 4 1
    1 2 3 4
    

    输出#1

    NO
    
  • 输入#2

    4 1
    4 3 1 2
    3 4 2 1
    

    输出#2

    YES
    
  • 输入#3

    4 3
    4 3 1 2
    3 4 2 1
    

    输出#3

    YES
    
  • 输入#4

    4 2
    4 3 1 2
    2 1 4 3
    

    输出#4

    YES
    
  • 输入#5

    4 1
    4 3 1 2
    2 1 4 3
    

    输出#5

    NO
    

说明/提示

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 kk 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.

首页