結果

問題 No.92 逃走経路
ユーザー ldsybldsyb
提出日時 2017-09-18 03:02:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 833 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 81,320 KB
実行使用メモリ 10,404 KB
最終ジャッジ日時 2024-04-25 15:06:41
合計ジャッジ時間 13,350 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
using namespace std;

struct edge{
	int to, cost;
	edge(int to, int cost){
		this->to = to;
		this->cost = cost;
	}
};

void dfs(vector<vector<edge>> &v, vector<int> &d, set<int> &ans, int k, int now, int count = 0){
	if(count == k){
		ans.insert(now + 1);
		return;
	}
	for(edge &e:v[now]){
		if(e.cost == d[count]){
			dfs(v, d, ans, k, e.to, count + 1);
		}
	}
}

int main(){
	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<edge>> v(n);
	while(m--){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		v[a].emplace_back(edge(b, c));
		v[b].emplace_back(edge(a, c));
	}
	vector<int> d(k);
	for(int &x:d) cin >> x;
	set<int> ans;
	for(int i = 0; i < n; i++){
		dfs(v, d, ans, k, i);
	}
	cout << ans.size() << endl;
	for(int x:ans) cout << x << ' ';
	cout << endl;
	return 0;
}
0