結果

問題 No.92 逃走経路
ユーザー kyo1
提出日時 2020-12-09 01:24:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 869 bytes
コンパイル時間 5,072 ms
コンパイル使用メモリ 204,096 KB
最終ジャッジ日時 2025-01-16 20:25:09
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 2
other AC * 6 TLE * 7 MLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, K;
  cin >> N >> M >> K;
  vector<vector<pair<int, int>>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].emplace_back(make_pair(b, c));
    G[b].emplace_back(make_pair(a, c));
  }
  vector<int> D(K);
  for (auto &&e : D) {
    cin >> e;
  }
  vector<int> res;
  function<void(int, int)> dfs = [&](int u, int i) {
    if (i == K) {
      res.emplace_back(u);
      return;
    }
    for (auto [v, c] : G[u]) {
      if (D[i] == c) {
        dfs(v, i + 1);
      }
    }
  };
  for (int i = 0; i < N; i++) {
    dfs(i, 0);
  }
  sort(res.begin(), res.end());
  cout << res.size() << '\n';
  for (const auto &e : res) {
    cout << e + 1 << (&e == &res.back() ? '\n' : ' ');
  }
  return 0;
}
0