結果

問題 No.92 逃走経路
ユーザー DialBird
提出日時 2017-03-10 07:01:19
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 916 bytes
コンパイル時間 1,576 ms
コンパイル使用メモリ 178,216 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-24 07:34:03
合計ジャッジ時間 2,543 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,first,last) for (int i=first;i<last;++i)
#define MAX(x,y) (x > y ? x : y)
#define MIN(x,y) (x < y ? x : y)

int N,M,K;

int main(){
  cin >> N >> M >> K;
  vector<map<int, vector<int>>> town_info(N+1);

  REP(i,0,M){
    int a,b,c;
    cin >> a >> b >> c;
    town_info[a][c].push_back(b);
    town_info[b][c].push_back(a);
  }

  vector<int> d_list(K);
  REP(i,0,K){
    cin >> d_list[i];
  }

  set<int> candidate_towns;
  REP(i,0,N){
    candidate_towns.insert(i + 1);
  }

  for (int d: d_list) {
    set<int> rest_towns;
    for (int c: candidate_towns) {
      if (town_info[c][d].size() != 0) {
        for (int t: town_info[c][d]) {
          rest_towns.insert(t);
        }
      }
    }
    candidate_towns = rest_towns;
  }

  cout << candidate_towns.size() << endl;
  for (int c: candidate_towns) {
    cout << c << " ";
  }
  cout << endl;
}
0