結果
| 問題 |
No.482 あなたの名は
|
| ユーザー |
ngtkana
|
| 提出日時 | 2020-03-18 01:02:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 799 bytes |
| コンパイル時間 | 2,065 ms |
| コンパイル使用メモリ | 198,652 KB |
| 最終ジャッジ日時 | 2025-01-09 07:35:59 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include<bits/stdc++.h>
using lint=long long;
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint n,k;std::cin>>n>>k;
std::vector<lint>p(n);
for(lint i=0;i<n;i++){
lint x;std::cin>>x;
p.at(i)=x-1;
}
lint cost=n;
std::vector<lint>ckd(n);
for(lint i=0;i<n;i++){
if(ckd.at(i))continue;
std::queue<lint>que;
que.push(i);
ckd.at(i)=true;
while(!que.empty()){
lint x=que.front();que.pop();
lint y=p.at(x);
if(!ckd.at(y)){
que.push(y);
ckd.at(y)=true;
}
}
cost--;
}
std::cout<<(cost<=k&&(k-cost)%2==0?"YES":"NO")<<'\n';
}
ngtkana