結果

問題 No.92 逃走経路
ユーザー motimoti
提出日時 2015-07-17 18:20:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 1,265 bytes
コンパイル時間 1,061 ms
コンパイル使用メモリ 106,852 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 17:00:10
合計ジャッジ時間 2,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int main() {

  int N, M, K; cin >> N >> M >> K;
  unordered_map<int, unordered_map<int, vector<int>>> cab;
  rep(i, M) {
    int a, b, c; cin >> a >> b >> c;
    cab[c][a].push_back(b);
    cab[c][b].push_back(a);
  }
  vector<int> d(K);
  rep(i, K) {
    cin >> d[i];
  }

  vector<int> now[1001];
  rep(i, N) now[0].push_back(i+1);
  rep(i, K) {
    auto& ab = cab[d[i]];
    rep(pre, N) {
      vector<int> next;
      rep(k, now[pre].size()) {
        auto& tar = ab[now[pre][k]];
        std::copy(tar.begin(), tar.end(), back_inserter(next));
      }
      std::sort(next.begin(), next.end());
      next.erase(std::unique(next.begin(), next.end()), next.end());
      now[pre] = next;
    }
  }

  vector<int> ans;  
  rep(i, N) {
    rep(j, now[i].size()) {
      ans.push_back(now[i][j]);
    }
  }

  std::sort(ans.begin(), ans.end());

  cout << ans.size() << endl;
  rep(i, ans.size()) {
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}
0