結果

問題 No.92 逃走経路
ユーザー togatogatogatoga
提出日時 2015-09-09 22:50:32
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 263 ms / 5,000 ms
コード長 904 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 78,000 KB
実行使用メモリ 146,852 KB
最終ジャッジ日時 2023-09-26 10:19:33
合計ジャッジ時間 4,714 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 263 ms
94,136 KB
testcase_01 AC 73 ms
76,152 KB
testcase_02 AC 73 ms
76,636 KB
testcase_03 AC 75 ms
76,676 KB
testcase_04 AC 74 ms
76,508 KB
testcase_05 AC 195 ms
135,892 KB
testcase_06 AC 182 ms
140,720 KB
testcase_07 AC 180 ms
140,736 KB
testcase_08 AC 92 ms
80,496 KB
testcase_09 AC 125 ms
89,652 KB
testcase_10 AC 187 ms
81,336 KB
testcase_11 AC 225 ms
145,624 KB
testcase_12 AC 225 ms
145,904 KB
testcase_13 AC 206 ms
146,852 KB
testcase_14 AC 211 ms
97,540 KB
testcase_15 AC 202 ms
84,404 KB
testcase_16 AC 198 ms
82,972 KB
testcase_17 AC 200 ms
82,764 KB
testcase_18 AC 169 ms
81,868 KB
testcase_19 AC 107 ms
79,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10000000)
N,M,K = map(int, raw_input().split())

graph = [[] for i in range(N)]
ans = set()
visit = [[-1 for i in range(K)] for j in range(N)]

def dfs(pos, path):
    if (path == K):
        return True
    global visit
    global d
    
    if (visit[pos][path] != -1):
        return visit[pos][path]
    ok = False
    for next in graph[pos]:
        if (d[path] != next[1]):
            continue
        ok |= dfs(next[0], path + 1)
    visit[pos][path] = ok
    return ok

for i in range(M):
    a,b,c = map(int, raw_input().split())
    a -= 1;b -= 1
    graph[a].append((b, c))
    graph[b].append((a, c))
d = map(int, raw_input().split())
d.reverse()
for i in range(N):
    if (dfs(i, 0)):
        ans.add(i)

ans = list(ans)
ans.sort()
ans = map(lambda x : x + 1, ans)
print len(ans)
if (len(ans) == 1):
    print ans[0]
else:
    print " ".join(map(str, ans))
0