結果

問題 No.92 逃走経路
ユーザー koyumeishikoyumeishi
提出日時 2014-12-07 21:30:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,273 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 83,148 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 10:40:59
合計ジャッジ時間 1,910 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

struct edge{
	int to;
	int cost;
};

vector<vector<int> > memo;

bool dfs( vector<vector<edge> > &G, vector<int> &d, int pos, int x){
	if(memo[pos][x] >= 0) return memo[pos][x] == 1;
	if( x==0 ){
		return true;
	}
	bool ret = false;
	for(int i=0; i<G[pos].size(); i++){
		if( G[pos][i].cost == d[x-1] ){
			ret |= dfs(G,d, G[pos][i].to, x-1);
		}
		if(ret){
			memo[pos][x] = 1;
			return ret;
		}
	}
	memo[pos][x] = 0;
	return ret;
}


int main(){
	int N,M,K;
	cin >> N >> M >> K;
	vector< vector<edge> > G(N);
	for(int i=0; i<M; i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--;
		b--;
		
		G[a].push_back( (edge){b, c} );
		G[b].push_back( (edge){a, c} );
	}
	
	vector<int> d(K);
	for(int i=0; i<K; i++) cin >> d[i];

	memo = vector<vector<int> >(N, vector<int>(K+1, -1) );

	vector<int> ans;
	for(int i=0; i<N; i++){
		if(dfs(G, d, i, K) == true){
			ans.push_back(i);
		}
	}

	cout << ans.size() << endl;
	for(int i=0; i<ans.size(); i++){
		cout << ans[i]+1 << (i==ans.size()-1?"\n" : " ");
	}
	
	
	return 0;
}
0