結果

問題 No.92 逃走経路
ユーザー ldsybldsyb
提出日時 2017-06-18 14:59:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 1,135 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 88,624 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 19:46:03
合計ジャッジ時間 4,538 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 13 ms
6,940 KB
testcase_06 AC 9 ms
6,944 KB
testcase_07 AC 10 ms
6,940 KB
testcase_08 AC 252 ms
6,944 KB
testcase_09 AC 251 ms
6,944 KB
testcase_10 AC 122 ms
6,944 KB
testcase_11 AC 155 ms
6,944 KB
testcase_12 AC 258 ms
6,940 KB
testcase_13 AC 240 ms
6,940 KB
testcase_14 AC 236 ms
6,940 KB
testcase_15 AC 241 ms
6,940 KB
testcase_16 AC 237 ms
6,944 KB
testcase_17 AC 231 ms
6,944 KB
testcase_18 AC 103 ms
6,940 KB
testcase_19 AC 52 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;

template <typename T>
string join(vector<T> v, string str){
	stringstream ss;
	for(int i = 0; i < v.size(); i++){
		if(i) ss << str;
		ss << v[i];
	}
	return ss.str();
}

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

int main(){
	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<edge>> e(n);
	while(m--){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		e[a].emplace_back(edge(b, c));
		e[b].emplace_back(edge(a, c));
	}
	int d[k];
	for(int i = 0; i < k; i++) cin >> d[i];
	vector<vector<bool>> puni(k + 1, vector<bool>(n, false));
	for(int i = 0; i < n; i++) puni[0][i] = true;
	for(int i = 1; i <= k; i++) for(int j = 0; j < n; j++) if(puni[i - 1][j]) for(auto& ee:e[j]) if(ee.cost == d[i - 1]) puni[i][ee.to] = true;

	for(int i = 0; i < k + 1; i++){
		for(int j = 0; j < n; j++) cerr << puni[i][j] << ' ';
		cerr << endl;
	}

	vector<int> ans;
	for(int i = 0; i < n; i++) if(puni[k][i]) ans.emplace_back(i + 1);
	cout << ans.size() << endl;
	cout << join(ans, " ") << endl;
}
0