#include using namespace std; class DisjointSet { private: class Node { friend DisjointSet; std::size_t parent; std::size_t size; Node(const std::size_t parent, const std::size_t size) : parent(parent), size(size) {} }; std::vector nodes; public: explicit DisjointSet(const std::size_t n) : nodes(n, Node(n, 1)) {} std::size_t size() const { return nodes.size(); } std::size_t size(const std::size_t x) { return nodes[root(x)].size; } std::size_t root(const std::size_t x) { if (nodes[x].parent == size()) return x; return nodes[x].parent = root(nodes[x].parent); } bool is_same(const std::size_t x, const std::size_t y) { return root(x) == root(y); } bool unite(const std::size_t x, const std::size_t y) { std::size_t rx = root(x), ry = root(y); if (rx == ry) return false; if (nodes[rx].size < nodes[ry].size) std::swap(rx, ry); nodes[rx].size += nodes[ry].size; nodes[ry].parent = rx; return true; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; int64_t K; cin >> N >> K; DisjointSet ds(N); for (int i = 0; i < N; i++) { int d; cin >> d; d--; ds.unite(i, d); } int64_t count = 0; set roots; for (int i = 0; i < N; i++) { if (roots.find(ds.root(i)) != roots.end()) continue; count += ds.size(i) - 1; roots.insert(ds.root(i)); } if (count > K || (K - count) % 2 != 0) { cout << "NO" << '\n'; } else { cout << "YES" << '\n'; } return 0; }