結果

問題 No.482 あなたの名は
ユーザー notetonousnotetonous
提出日時 2017-08-03 17:55:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 544 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 56,868 KB
実行使用メモリ 4,612 KB
最終ジャッジ日時 2023-08-02 00:56:18
合計ジャッジ時間 3,397 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 54 ms
4,520 KB
testcase_16 AC 52 ms
4,384 KB
testcase_17 AC 54 ms
4,380 KB
testcase_18 AC 54 ms
4,380 KB
testcase_19 AC 55 ms
4,384 KB
testcase_20 AC 54 ms
4,612 KB
testcase_21 AC 54 ms
4,380 KB
testcase_22 AC 54 ms
4,608 KB
testcase_23 AC 53 ms
4,384 KB
testcase_24 AC 56 ms
4,480 KB
testcase_25 AC 54 ms
4,472 KB
testcase_26 AC 54 ms
4,380 KB
testcase_27 AC 55 ms
4,384 KB
testcase_28 AC 53 ms
4,384 KB
testcase_29 AC 52 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int G[200002];
bool used[200002];
long long int Count;
void dfs(int v){
  //cout << v << endl;
  used[v]=true;
  int n=G[v];
  if(!used[n])dfs(n);
}
int main(){
  long long int N;
  long long int K;
  cin >> N >> K;
  for(int i=1;i<=N;i++){
    int d;
    cin >> d;
    G[i]=d;
    
  }
  for(int i=1;i<=N;i++){
    if(!used[i]){
      dfs(i);
      Count++;
    }
  }
  Count=N-Count;
  if(Count<=K && K%2==Count%2)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}
  
0