結果

問題 No.482 あなたの名は
ユーザー 双六双六
提出日時 2020-09-07 02:04:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 1,333 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 113,160 KB
最終ジャッジ日時 2023-08-19 14:38:04
合計ジャッジ時間 7,205 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,444 KB
testcase_01 AC 76 ms
71,372 KB
testcase_02 AC 78 ms
71,320 KB
testcase_03 AC 78 ms
71,592 KB
testcase_04 AC 78 ms
71,416 KB
testcase_05 AC 80 ms
71,424 KB
testcase_06 AC 77 ms
71,424 KB
testcase_07 AC 122 ms
76,272 KB
testcase_08 AC 86 ms
76,084 KB
testcase_09 AC 79 ms
71,600 KB
testcase_10 AC 86 ms
76,060 KB
testcase_11 AC 83 ms
76,244 KB
testcase_12 AC 85 ms
76,236 KB
testcase_13 AC 88 ms
75,932 KB
testcase_14 AC 87 ms
76,100 KB
testcase_15 AC 217 ms
112,828 KB
testcase_16 AC 190 ms
113,108 KB
testcase_17 AC 191 ms
112,408 KB
testcase_18 AC 195 ms
112,908 KB
testcase_19 AC 200 ms
112,884 KB
testcase_20 AC 197 ms
113,048 KB
testcase_21 AC 193 ms
113,004 KB
testcase_22 AC 183 ms
113,160 KB
testcase_23 AC 189 ms
112,828 KB
testcase_24 AC 192 ms
112,792 KB
testcase_25 AC 184 ms
112,840 KB
testcase_26 AC 185 ms
113,056 KB
testcase_27 AC 191 ms
112,632 KB
testcase_28 AC 186 ms
112,876 KB
testcase_29 AC 140 ms
112,828 KB
testcase_30 AC 79 ms
71,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class UnionFind:
	def __init__(self, n):
		self.par = [i for i in range(n + 1)]
		self.rank = [0] * (n + 1)
		self.size = [1] * (n + 1)

	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]

	def same_check(self, x, y):
		return self.find(x) == self.find(y)

	def union(self, x, y):
		x = self.find(x); y = self.find(y)
		if self.rank[x] < self.rank[y]:
			if self.same_check(x, y) != True:
				self.size[y] += self.size[x]
				self.size[x] = 0
			self.par[x] = y
		else:
			if self.same_check(x, y) != True:
				self.size[x] += self.size[y]
				self.size[y] = 0
			self.par[y] = x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1

	def siz(self, x):
		x = self.find(x)
		return self.size[x]

#処理内容
def main():
	N, K = getlist()
	D = getlist()
	UF = UnionFind(N)
	for i in range(N):
		if i != D[i] - 1:
			UF.union(i, D[i] - 1)

	for i in range(N):
		UF.par[i] = UF.find(i)

	S = 0
	for i in UF.size:
		if i != 0:
			S += i - 1

	if S <= K and (K - S) % 2 == 0:
		print("YES")
	else:
		print("NO")


if __name__ == '__main__':
	main()
0