結果

問題 No.92 逃走経路
ユーザー Tawara
提出日時 2015-10-20 19:47:16
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 516 bytes
コンパイル時間 1,102 ms
コンパイル使用メモリ 7,196 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-07-22 11:05:46
合計ジャッジ時間 8,083 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 RE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,K = map(int,raw_input().split())
E = [[] for i in xrange(N)]
ans = set()
for i in xrange(M):
	a,b,c = map(int,raw_input().split())
	a -= 1; b -= 1
	E[a].append((b,c))
	E[b].append((a,c))
d = map(int,raw_input().split())
d.reverse()
now = True
def dfs(h,k):
	global now
	if k == K or now:
		now = True
		return True
	res = False
	for nxt,c in E[h]:
		if c == d[k]:
			res |= dfs(nxt,k+1)
	return res
for i in xrange(N):
	now = False
	if dfs(i,0):
		ans.add(i+1)
print len(ans)
print " ".join(map(str,sorted(ans)))
0