結果

問題 No.92 逃走経路
ユーザー togatogatogatoga
提出日時 2015-09-09 22:50:32
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 242 ms / 5,000 ms
コード長 904 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 76,844 KB
実行使用メモリ 84,096 KB
最終ジャッジ日時 2024-07-19 05:07:42
合計ジャッジ時間 4,470 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 242 ms
83,364 KB
testcase_01 AC 73 ms
75,520 KB
testcase_02 AC 73 ms
75,436 KB
testcase_03 AC 76 ms
75,520 KB
testcase_04 AC 75 ms
75,252 KB
testcase_05 AC 129 ms
78,992 KB
testcase_06 AC 109 ms
79,360 KB
testcase_07 AC 109 ms
79,104 KB
testcase_08 AC 92 ms
79,488 KB
testcase_09 AC 116 ms
82,432 KB
testcase_10 AC 181 ms
80,128 KB
testcase_11 AC 142 ms
82,712 KB
testcase_12 AC 153 ms
84,096 KB
testcase_13 AC 124 ms
83,232 KB
testcase_14 AC 178 ms
82,688 KB
testcase_15 AC 191 ms
82,432 KB
testcase_16 AC 204 ms
81,536 KB
testcase_17 AC 199 ms
81,676 KB
testcase_18 AC 170 ms
80,188 KB
testcase_19 AC 106 ms
78,856 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