結果

問題 No.92 逃走経路
ユーザー けーむけーむ
提出日時 2020-03-26 11:08:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,546 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 181,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 12:13:05
合計ジャッジ時間 3,161 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll n, m, k;
vector<vector<pair<ll, ll>>> g;
vector<ll> d;
vector<vector<bool>> dp;

void dfs(ll v, ll depth = 0) {
    if (dp[v][depth]) return;
    dp[v][depth] = true;
    if (depth == (k - 1)) return;
    for(auto x : g[v]) {
        ll u = x.first, c = x.second;
        if (d[depth + 1] == c) {
            dfs(u, depth + 1);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n >> m >> k;
    g.resize(n);
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].push_back(make_pair(b, c));
        g[b].push_back(make_pair(a, c));
    }
    d.resize(k);
    rep(i, k) cin >> d[i];
    dp.resize(n, vector<bool>(k, false));
    rep(v, n) {
        for(auto x : g[v]) {
            ll u = x.first, c = x.second;
            if (c == d[0]) dfs(u);
        }
    }
    vector<ll> ans;
    rep(i, n) {
        if (dp[i][k - 1]) ans.push_back(i);
    }
    printf("%lld\n", sz(ans));
    rep(i, sz(ans)) printf("%lld%s", ans[i] + 1, (i == (sz(ans) - 1)) ? "\n" : " ");
    return 0;
}
0