結果

問題 No.92 逃走経路
ユーザー togatogatogatoga
提出日時 2015-09-09 22:50:07
言語 Python2
(2.7.18)
結果
AC  
実行時間 693 ms / 5,000 ms
コード長 904 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 6,496 KB
実行使用メモリ 7,648 KB
最終ジャッジ日時 2023-09-26 10:19:28
合計ジャッジ時間 4,981 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
7,588 KB
testcase_01 AC 11 ms
5,908 KB
testcase_02 AC 12 ms
5,904 KB
testcase_03 AC 12 ms
5,908 KB
testcase_04 AC 11 ms
6,032 KB
testcase_05 AC 667 ms
6,828 KB
testcase_06 AC 136 ms
6,776 KB
testcase_07 AC 134 ms
6,720 KB
testcase_08 AC 22 ms
7,532 KB
testcase_09 AC 89 ms
7,528 KB
testcase_10 AC 679 ms
7,088 KB
testcase_11 AC 620 ms
7,232 KB
testcase_12 AC 693 ms
7,648 KB
testcase_13 AC 52 ms
7,228 KB
testcase_14 AC 60 ms
7,396 KB
testcase_15 AC 88 ms
7,384 KB
testcase_16 AC 77 ms
7,224 KB
testcase_17 AC 106 ms
7,428 KB
testcase_18 AC 105 ms
7,076 KB
testcase_19 AC 102 ms
6,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