結果

問題 No.2674 k-Walk on Bipartite
ユーザー shobonvipshobonvip
提出日時 2024-03-15 21:55:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 687 ms / 2,000 ms
コード長 1,391 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 99,492 KB
最終ジャッジ日時 2024-03-15 21:55:27
合計ジャッジ時間 10,605 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,620 KB
testcase_01 AC 43 ms
55,620 KB
testcase_02 AC 43 ms
55,620 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 41 ms
53,460 KB
testcase_05 AC 40 ms
53,460 KB
testcase_06 AC 39 ms
53,460 KB
testcase_07 AC 443 ms
96,368 KB
testcase_08 AC 550 ms
92,756 KB
testcase_09 AC 329 ms
93,012 KB
testcase_10 AC 646 ms
95,916 KB
testcase_11 AC 449 ms
90,624 KB
testcase_12 AC 584 ms
92,976 KB
testcase_13 AC 371 ms
91,188 KB
testcase_14 AC 140 ms
87,632 KB
testcase_15 AC 687 ms
99,492 KB
testcase_16 AC 575 ms
97,852 KB
testcase_17 AC 546 ms
92,680 KB
testcase_18 AC 231 ms
85,852 KB
testcase_19 AC 468 ms
93,136 KB
testcase_20 AC 369 ms
95,164 KB
testcase_21 AC 578 ms
93,816 KB
testcase_22 AC 582 ms
97,780 KB
testcase_23 AC 39 ms
53,460 KB
testcase_24 AC 38 ms
53,460 KB
testcase_25 AC 38 ms
53,460 KB
testcase_26 AC 38 ms
53,460 KB
testcase_27 AC 37 ms
53,460 KB
testcase_28 AC 39 ms
53,460 KB
testcase_29 AC 40 ms
53,460 KB
testcase_30 AC 38 ms
53,460 KB
testcase_31 AC 42 ms
53,460 KB
testcase_32 AC 38 ms
53,460 KB
testcase_33 AC 38 ms
53,460 KB
testcase_34 AC 38 ms
53,460 KB
testcase_35 AC 38 ms
53,460 KB
testcase_36 AC 39 ms
53,460 KB
testcase_37 AC 38 ms
53,460 KB
testcase_38 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n
	
	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]
	
	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return
		if self.parents[x] > self.parents[y]:
			x, y = y, x
		self.parents[x] += self.parents[y]
		self.parents[y] = x


n, m = map(int,input().split())
s, t, k = map(int,input().split())
s -= 1
t -= 1

if n == 1:
	print("No")
	exit()

ikeru = [[] for i in range(n)]
uf = UnionFind(n)
for i in range(m):
	a, b = map(int,input().split())
	a -= 1
	b -= 1
	ikeru[a].append(b)
	ikeru[b].append(a)
	uf.union(a, b)

if n == 2:
	if s == t:
		if k % 2 == 1:
			print("No")
			exit()
		if uf.find(0) != uf.find(1):
			print("Unknown")
			exit()
		print("Yes")
	else:
		if k % 2 == 0:
			print("No")
			exit()
		if uf.find(0) != uf.find(1):
			print("Unknown")
			exit()
		print("Yes")
	exit()

if uf.find(s) != uf.find(t):
	print("Unknown")
	exit()

from collections import deque

dst = [0] * n
tansaku = [0] * n
tansaku[s] = 1
mada = deque([])
mada.append(s)

while mada:
	i = mada.popleft()
	for j in ikeru[i]:
		if tansaku[j] == 0:
			tansaku[j] = 1
			mada.append(j)
			dst[j] = dst[i] + 1

if dst[t] % 2 != k % 2:
	print("No")
	exit()

if dst[t] <= k:
	print("Yes")
	exit()

print("Unknown")
0