結果

問題 No.482 あなたの名は
ユーザー tookunn_1213tookunn_1213
提出日時 2017-02-11 01:02:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 11,076 KB
実行使用メモリ 30,180 KB
最終ジャッジ日時 2023-08-28 16:18:14
合計ジャッジ時間 7,870 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,876 KB
testcase_01 AC 16 ms
7,924 KB
testcase_02 AC 16 ms
7,860 KB
testcase_03 AC 16 ms
7,940 KB
testcase_04 AC 15 ms
7,868 KB
testcase_05 AC 16 ms
7,956 KB
testcase_06 AC 16 ms
7,872 KB
testcase_07 AC 17 ms
8,484 KB
testcase_08 AC 17 ms
8,288 KB
testcase_09 AC 16 ms
7,796 KB
testcase_10 AC 16 ms
8,440 KB
testcase_11 AC 17 ms
8,256 KB
testcase_12 AC 16 ms
8,452 KB
testcase_13 AC 16 ms
8,468 KB
testcase_14 AC 17 ms
8,424 KB
testcase_15 AC 398 ms
30,180 KB
testcase_16 AC 404 ms
30,056 KB
testcase_17 AC 394 ms
30,120 KB
testcase_18 AC 405 ms
29,984 KB
testcase_19 AC 401 ms
30,152 KB
testcase_20 AC 400 ms
30,060 KB
testcase_21 AC 402 ms
30,116 KB
testcase_22 AC 386 ms
29,976 KB
testcase_23 AC 383 ms
30,008 KB
testcase_24 AC 408 ms
30,124 KB
testcase_25 AC 388 ms
30,108 KB
testcase_26 AC 392 ms
30,112 KB
testcase_27 AC 391 ms
29,984 KB
testcase_28 AC 390 ms
30,116 KB
testcase_29 AC 305 ms
30,044 KB
testcase_30 AC 15 ms
7,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
D = [int(i)-1 for i in input().split()]
cnt = 0
unionfind = [i for i in range(N)]
size = [1 for i in range(N)]
used = [False for i in range(N)]
def find(x):
	if unionfind[x] == x:
		return x
	unionfind[x] = find(unionfind[x])
	return unionfind[x]
def unite(x,y):
	x = find(x)
	y = find(y)
	if x == y:
		return
	if x < y:
		unionfind[y] = x
		size[x] += size[y]
	else:
		unionfind[x] = y
		size[y] += size[x]
for i in range(N):
	a = D[i]
	b = D[D[i]]
	unite(a,b)
for i in range(N):
	if not used[find(i)]:
		cnt += size[find(i)]-1
		used[find(i)] = True
def check():
	if K < cnt:
		return False
	return cnt % 2 == K % 2
if check():
	print('YES')
else:
	print('NO')
0