結果

問題 No.92 逃走経路
ユーザー tkzw_21tkzw_21
提出日時 2014-12-08 12:40:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,227 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 81,592 KB
実行使用メモリ 17,516 KB
最終ジャッジ日時 2023-09-02 11:40:40
合計ジャッジ時間 7,490 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 TLE -
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 <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;
struct edge{
	int from,to,cost,num;
};
vector<vector<edge> >es;
vector<int> d;
vector<int> ans;
bool used[1010];

void dfs(int v,int k,int maxk){
	if(k == maxk){
		ans.push_back(v);
		return;
	}
	for(int i=0;i<es[v].size();i++){
		if(es[v][i].cost == d[k] && !used[es[v][i].num]){
			used[es[v][i].num] = true;
			dfs(es[v][i].to,k+1,maxk);
			used[es[v][i].num] = false;
		}
	}
}

int main(void){
	int n,m,k;
	cin >> n >> m >> k;
	es.resize(n);
	for(int i=0;i<m;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		es[a].push_back((edge){a,b,c,i});
		es[b].push_back((edge){b,a,c,i});
	}
	d.resize(k);
	for(int i=0;i<k;i++){
		cin >> d[i];
	}

	for(int i=0;i<n;i++){
		dfs(i,0,k);
	}
	sort(ans.begin(),ans.end());
	vector<int> ret;
	int pre = -1;
	for(int i=0;i<ans.size();i++){
		if(ans[i] != pre){
			//cout << ans[i] << endl;
			pre = ans[i];
			ret.push_back(ans[i]);
		}
	}

	cout << ret.size() << endl;
	for(int i=0;i<ret.size();i++){
		cout << ret[i]+1;
		if(i != ret.size()-1)cout << " ";
	}
	cout << endl;
	return 0;
}
0