// yukicoder: No.482 あなたの名は // 2019.7.29 bal4u #include #include typedef long long ll; #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } ll In() { // 非負整数の入力 ll n = 0; int c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void outs(char *s) { while (*s) pc(*s++); pc('\n'); } /* UNION-FIND library */ #define MAX 200003 int uni[MAX]; void init(int n) { memset(uni, -1, sizeof(int)*n); } int root(int i) { if (uni[i] < 0) return i; return uni[i] = root(uni[i]); } int connected(int p, int q) { return root(p) == root(q); } void unite(int p, int q) { int t; p = root(p), q = root(q); if (p == q) return; if (uni[p] > uni[q]) t = p, p = q, q = t; uni[p] += uni[q], uni[q] = p; } int size(int i) { return -uni[root(i)]; } int N; ll K; int main() { int i, ans; N = in(), K = In(), init(N+1); for (i = 1; i <= N; i++) unite(in(), i); ans = 0; for (i = 1; i <= N; i++) if (root(i) == i && uni[i] < -1) ans += -uni[i]-1; outs(ans <= K && ((K - ans) & 1) == 0? "YES": "NO"); return 0; }