結果

問題 No.92 逃走経路
ユーザー hogeover30hogeover30
提出日時 2015-01-29 20:28:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 76,640 KB
実行使用メモリ 4,648 KB
最終ジャッジ日時 2023-09-05 07:55:08
合計ジャッジ時間 2,480 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
4,588 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 119 ms
4,384 KB
testcase_10 AC 32 ms
4,484 KB
testcase_11 AC 52 ms
4,516 KB
testcase_12 AC 120 ms
4,412 KB
testcase_13 AC 55 ms
4,376 KB
testcase_14 AC 61 ms
4,400 KB
testcase_15 AC 77 ms
4,412 KB
testcase_16 AC 58 ms
4,648 KB
testcase_17 AC 57 ms
4,576 KB
testcase_18 AC 20 ms
4,376 KB
testcase_19 AC 10 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <unordered_set>
#include <set>
using namespace std;
int n, m, k, d[1010], visited[101][1010];
unordered_set<int> cost[101][101];
set<int> res;

void dfs(int p, int i)
{
    if (i==k) {
        res.insert(p);
        return;
    }
    visited[p][i]=1;
    for(int j=1;j<=n;++j)
        if (cost[p][j].count(d[i]) and !visited[j][i+1])
            dfs(j, i+1);
}

int main()
{
    cin>>n>>m>>k;
    for(int i=0;i<m;++i) {
        int a, b, c; cin>>a>>b>>c;
        cost[a][b].insert(c);
        cost[b][a].insert(c);
    }
    for(int i=0;i<k;++i) cin>>d[i];
    for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
        if (cost[i][j].count(d[0])) dfs(i, 1);

    cout<<res.size()<<endl;
    for(int v: res) cout<<v<<' ';
    cout<<endl;
}
0