結果
| 問題 |
No.482 あなたの名は
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2024-09-29 23:47:36 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 559 bytes |
| コンパイル時間 | 1,480 ms |
| コンパイル使用メモリ | 105,540 KB |
| 実行使用メモリ | 16,512 KB |
| 最終ジャッジ日時 | 2024-09-29 23:47:41 |
| 合計ジャッジ時間 | 4,098 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
#include<atcoder/dsu>
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n,k;
cin>>n>>k;
vector<ll> d(n);
for(int i = 0;i<n;i++) cin>>d[i];
atcoder::dsu uf(n);
for(int i = 0;i<n;i++) {
d[i]--;
uf.merge(i,d[i]);
}
ll need = 0;
for(auto now:uf.groups()){
need += now.size() - 1;
}
if(need<=k&&need%2==k%2){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
momoyuu