結果

問題 No.92 逃走経路
ユーザー beetbeet
提出日時 2018-10-15 16:36:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 918 bytes
コンパイル時間 2,444 ms
コンパイル使用メモリ 203,160 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 20:28:34
合計ジャッジ時間 3,199 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m,k;
  cin>>n>>m>>k;
  using P = pair<Int, Int>;
  vector<vector<P> > G(n);
  for(Int i=0;i<m;i++){
    Int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,c);
  }
  vector<Int> d(k);
  for(Int i=0;i<k;i++) cin>>d[i];

  vector<Int> dp(n,1);
  for(Int i=0;i<k;i++){
    vector<Int> nx(n,0);
    for(Int v=0;v<n;v++)
      for(auto [u, c]:G[v])
	if(d[i]==c) nx[u]|=dp[v];
    swap(dp,nx);
  }

  vector<Int> ans;
  for(Int i=0;i<n;i++)
    if(dp[i]) ans.emplace_back(i);

  cout<<ans.size()<<endl;
  for(Int i=0;i<(Int)ans.size();i++){
    if(i) cout<<" ";
    cout<<ans[i]+1;
  }
  cout<<endl;
  return 0;
}
0