結果

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

ソースコード

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;
  }
  queue<pair<int, int>> que;
  for (int i = 0; i < N; i++) {
    que.push(make_pair(i, 0));
  }
  vector<int> res;
  while (!que.empty()) {
    auto [u, i] = que.front();
    que.pop();
    if (i == K) {
      res.emplace_back(u);
      continue;
    }
    for (auto [v, c] : G[u]) {
      if (D[i] == c) {
        que.push(make_pair(v, i + 1));
      }
    }
  }
  sort(res.begin(), res.end());
  cout << res.size() << '\n';
  for (const auto &e : res) {
    cout << e + 1 << (&e == &res.back() ? '\n' : ' ');
  }
  return 0;
}
0