結果

問題 No.92 逃走経路
コンテスト
ユーザー fura
提出日時 2020-04-15 22:20:10
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 794 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,378 ms
コンパイル使用メモリ 216,216 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-09 13:24:48
合計ジャッジ時間 2,602 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

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

using namespace std;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

int main(){
	int n,m,k; scanf("%d%d%d",&n,&m,&k);
	weighted_graph<int> G(n);
	rep(i,m){
		int u,v,c; scanf("%d%d%d",&u,&v,&c); u--; v--;
		G[u].emplace_back(v,c);
		G[v].emplace_back(u,c);
	}

	bool dp[1001][100]={};
	rep(u,n) dp[0][u]=true;
	rep(t,k){
		int d; scanf("%d",&d);
		rep(u,n) if(dp[t][u]) {
			for(auto e:G[u]) if(e.wt==d) {
				dp[t+1][e.to]=true;
			}
		}
	}

	vector<int> ans;
	rep(u,n) if(dp[k][u]) ans.emplace_back(u);
	printf("%lu\n",ans.size());
	rep(i,ans.size()) printf("%d%c",ans[i]+1,i+1<ans.size()?' ':'\n');

	return 0;
}
0