結果

問題 No.583 鉄道同好会
ユーザー KoshStormKoshStorm
提出日時 2017-10-28 15:39:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 996 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-05-01 20:56:45
合計ジャッジ時間 3,136 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 29 ms
11,008 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 28 ms
10,880 KB
testcase_04 AC 38 ms
12,800 KB
testcase_05 AC 27 ms
11,008 KB
testcase_06 AC 28 ms
10,880 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 AC 28 ms
10,880 KB
testcase_09 AC 29 ms
10,880 KB
testcase_10 AC 34 ms
12,800 KB
testcase_11 AC 131 ms
12,928 KB
testcase_12 AC 164 ms
12,800 KB
testcase_13 AC 158 ms
12,800 KB
testcase_14 AC 154 ms
12,672 KB
testcase_15 AC 194 ms
12,800 KB
testcase_16 AC 342 ms
12,672 KB
testcase_17 AC 412 ms
12,800 KB
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#C問題:鉄道同好会


N,M = map(int,input().split(" "))


array = [[False]*N for i in range(N)]
end = 0
count = 0
end_i = []
val = []
table = []

def search (i,j,table):
	global array
	global count
	global end_i

	table.append(i)
	tmp = []

	count += 1	

	array[i][j] = False
	array[j][i] = False

	for k in range(N):
		if array[j][k]:
			if search(j,k,table):
				tmp.append(True)
			else:
				tmp.append(False)

	if tmp == []:
		return ((j in table) or (j == end_i[1]))

	else:
		return all(tmp)

for i in range(M):
	Sa,Sb = map(int,input().split(" "))
	array[Sa][Sb] = True
	array[Sb][Sa] = True



#オイラーグラフか半オイラーグラフかの判定
for i in range(N):
	num = array[i].count(True)
	if num%2 == 1:
		end += 1
		end_i.append(i)
		if end >= 3:
			print("NO")
			exit(0)


if end == 0:
	end_i.append(Sa)
	end_i.append(Sa)


for i in range(N):
	if array[end_i[0]][i]:
		val.append(search(end_i[0],i,[]))


if all(val) and count == M:
	print("YES")
else:
	print("NO")
0