結果

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

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,last) for (int i=0;i<last;i++)
#define prints(str) cout << str << " ";
#define printn(str) cout << str << endl;

typedef pair<int, int> p_ii;
typedef long long ll;

const int MAX_N = 100;
const int MAX_K = 1000;
map<int, vector<int>> G[MAX_N];
int d[MAX_K];

int main(){
  int N, M, K;
  cin >> N >> M >> K;
  REP(i,M){
    // aは0からN-1にする
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    G[a][c].push_back(b);
    G[b][c].push_back(a);
  }

  REP(i,K){ cin >> d[i]; }

  set<int> candidate;
  REP(i,N) candidate.insert(i);

  REP(i,K){
    int pay = d[i];
    set<int> new_candidate;
    for (auto c: candidate){
      if (!G[c][pay].empty()) {
        for (auto t: G[c][pay]){
          new_candidate.insert(t);
        }
      }
    }
    candidate = new_candidate;
  }

  printn(candidate.size());
  for(auto c: candidate) {
    prints(c+1);
  }
  cout << endl;
}
0