結果
問題 |
No.482 あなたの名は
|
ユーザー |
|
提出日時 | 2020-04-15 10:00:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 653 bytes |
コンパイル時間 | 799 ms |
コンパイル使用メモリ | 74,212 KB |
最終ジャッジ日時 | 2025-01-09 19:15:26 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <iostream> #include <vector> using lint = long long; void solve() { int n; lint k; std::cin >> n >> k; std::vector<int> xs(n); for (auto& x : xs) { std::cin >> x; --x; } k -= n; std::vector<bool> visited(n, false); for (int v = 0; v < n; ++v) { if (visited[v]) continue; ++k; while (!visited[v]) { visited[v] = true; v = xs[v]; } } std::cout << (k < 0 || k % 2 != 0 ? "NO" : "YES") << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }