結果

問題 No.92 逃走経路
ユーザー tkzw_21tkzw_21
提出日時 2014-12-09 20:40:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,397 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 76,300 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-02 12:13:30
合計ジャッジ時間 1,879 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 5 ms
4,384 KB
testcase_07 AC 5 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 4 ms
4,384 KB
testcase_10 WA -
testcase_11 AC 12 ms
4,384 KB
testcase_12 AC 12 ms
4,384 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <map>
#include <utility>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cmath>
#define ll long long

using namespace std;

struct e{
    int to,cost;
};

vector<vector<e> >es;
vector<int> costs;
vector<int> ans;

int used[101][1001];
int ek;
void dfs(int v,int k){
    if(used[v][k] == 1)return;
    used[v][k] = 1;
    if(k == ek){
        ans.push_back(v);
        return;
    }
    for(int i=0;i<es[v].size();i++){
        if(es[v][i].cost == costs[k])dfs(es[v][i].to,k+1);
    }
}


int main(void){
	int n,m;
    cin >> n >> m >> ek;
    es.resize(n);costs.resize(ek);
    for(int i=0;i<m;i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        es[a].push_back(e{b,c});
        es[b].push_back(e{a,c});
    }
    for(int i=0;i<ek;i++){
        cin >> costs[i];
    }

    for(int i=0;i<n;i++){
        memset(used,0,sizeof(0));
        dfs(i,0);
    }
    vector<int> ret;
    int pre = -1;
    for(int i=0;i<ans.size();i++){
        if(pre != ans[i]){
            ret.push_back(ans[i]);
            pre = ans[i];
        }
    }

    cout << ret.size() << endl;
    for(int i=0;i<ret.size();i++){
        cout << ret[i]+1;
        if(i!=ret.size()-1)cout << " ";
        else cout << endl;
    }

    return 0;
}
0