結果

問題 No.92 逃走経路
ユーザー kyo1kyo1
提出日時 2020-12-09 01:48:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 791 bytes
コンパイル時間 2,572 ms
コンパイル使用メモリ 214,300 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 16:03:02
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
  }
  set<int> st;
  for (int i = 0; i < N; i++) {
    st.insert(i);
  }
  for (int k = 0; k < K; k++) {
    set<int> nst;
    for (auto &u : st) {
      for (auto &[v, c] : G[u]) {
        if (D[k] == c) nst.insert(v);
      }
    }
    swap(st, nst);
  }
  cout << st.size() << '\n';
  for (const auto &e : st) {
    cout << e + 1 << ' ';
  }
  cout << '\n';
  return 0;
}
0