#include #include using namespace std; struct UF{ vector par, rank; UF(int n){ for(int i = 0; i < n; i++){ par.emplace_back(i); } rank.assign(n, 0); } int root(int x){ return par[x] == x ? x : par[x] = root(par[x]); } bool same(int x, int y){ return root(x) == root(y); } void unite(int x, int y){ x = root(x); y = root(y); if(rank[x] < rank[y]) par[x] = y; else{ par[y] = x; if(rank[x] == rank[y]) rank[x]++; } } }; int main(){ using int64 = int64_t; int64 n, k; cin >> n >> k; UF uf(n); for(int i = 0; i < n; i++){ int d; cin >> d; uf.unite(i, d - 1); } int64 a[n]{}; for(int i = 0; i < n; i++) a[uf.root(i)]++; int64 count = 0; for(int i = 0; i < n; i++) if(a[i]) count += a[i] - 1; cout << (count <= k && (k - count) % 2 == 0 ? "YES" : "NO") << endl; }