結果

問題 No.482 あなたの名は
ユーザー gigime
提出日時 2017-03-12 01:07:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 169,228 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-24 14:17:35
合計ジャッジ時間 3,869 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N,K;
vector<int> A;
bool vis [200001];

ll dfs(int curr)
{
	vis [curr] = true;
	if(vis [A [curr]]) return 1;
	return dfs(A [curr]) + 1;
}

int main()
{
	scanf("%lld%lld",&N,&K);
	A.assign(N + 1,0);
	FOR(i,1,N + 1){
		scanf("%d",&A [i]);
	}

	ll t = 0;
	FOR(i,1,N + 1) if(vis [i] == false){
		t += dfs(i) - 1;
	}

	if(t <= K && (K - t) % 2 == 0){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}

	return 0;
}
0