結果

問題 No.92 逃走経路
ユーザー togatogatogatoga
提出日時 2015-09-09 22:46:29
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 860 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 6,576 KB
実行使用メモリ 7,740 KB
最終ジャッジ日時 2023-09-26 10:19:13
合計ジャッジ時間 2,482 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
7,712 KB
testcase_01 AC 11 ms
5,888 KB
testcase_02 AC 12 ms
5,984 KB
testcase_03 AC 12 ms
6,032 KB
testcase_04 AC 11 ms
5,988 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 52 ms
7,224 KB
testcase_14 AC 56 ms
7,332 KB
testcase_15 AC 86 ms
7,332 KB
testcase_16 AC 76 ms
7,284 KB
testcase_17 AC 106 ms
7,536 KB
testcase_18 AC 104 ms
7,016 KB
testcase_19 AC 97 ms
7,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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