結果

問題 No.92 逃走経路
ユーザー ry0u_ydry0u_yd
提出日時 2015-09-02 09:53:37
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,410 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 76,968 KB
実行使用メモリ 274,568 KB
最終ジャッジ日時 2023-09-25 21:54:09
合計ジャッジ時間 13,552 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge {
    int from,to;
    int cost;

    edge(int t,int c) : to(t),cost(c) {}
    edge(int f,int t,int c) : from(f),to(t),cost(c) {}

    bool operator<(const edge &e) const {
        return cost < e.cost;
    }
};

vector<edge> G[105];
vector<int> v,ans;
int n,m,k;

void dfs(int now,int j) {
    if(j == k) {
        ans.push_back(now);
        return;
    }

    rep(i,G[now].size()) {
        edge e = G[now][i];
        if(e.cost == v[j]) {
            dfs(e.to,j+1);
        }
    }
}

int main() {
    cin >> n >> m >> k;

    rep(i,m) {
        int a,b,c;
        cin >> a >> b >> c;

        a--;
        b--;

        G[a].push_back(edge(b,c));
        G[b].push_back(edge(a,c));
    }

    v.resize(k);
    rep(i,k) cin >> v[i];

    rep(i,n) {
        dfs(i,0);
    }

    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    sort(ans.begin(),ans.end());

    cout << ans.size() << endl;
    rep(i,ans.size()) {
        cout << ans[i]+1;

        if(i == ans.size()-1) cout << endl;
        else cout << " ";
    }

    return 0;
}
0