結果

問題 No.92 逃走経路
ユーザー cielciel
提出日時 2014-12-07 20:36:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 942 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 80,160 KB
実行使用メモリ 7,904 KB
最終ジャッジ日時 2023-09-02 10:22:11
合計ジャッジ時間 2,546 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
5,632 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 46 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 25 ms
7,884 KB
testcase_10 AC 109 ms
5,316 KB
testcase_11 AC 79 ms
6,008 KB
testcase_12 AC 97 ms
7,904 KB
testcase_13 AC 14 ms
5,268 KB
testcase_14 AC 27 ms
5,508 KB
testcase_15 AC 40 ms
6,100 KB
testcase_16 AC 27 ms
5,284 KB
testcase_17 AC 28 ms
5,332 KB
testcase_18 AC 16 ms
4,380 KB
testcase_19 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
using namespace std;
set<int>result;
set<pair<int,int> >memo;

void dfs(/*const*/ vector<map<int,vector<int> > >&v,const vector<int> &d,int cur,int depth){
	if(depth==d.size()){
		result.insert(cur+1);
	}else{
		pair<int,int> x=make_pair(cur,depth);
		if(memo.find(x)!=memo.end())return;
		for(auto &it:v[cur][d[depth]]){
			dfs(v,d,it,depth+1);
		}
		memo.insert(x);
	}
}

int main(){
	int N,M,K;
	scanf("%d%d%d",&N,&M,&K);
	vector<map<int,vector<int> > >v(N);
	for(int i=0;i<M;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		v[a-1][c].push_back(b-1);
		v[b-1][c].push_back(a-1);
	}
	vector<int>d(K);
	for(int i=0;i<K;i++)scanf("%d",&d[i]);
	for(int i=0;i<N;i++)dfs(v,d,i,0);
	printf("%d\n",result.size());
	bool f=false;
	for(auto &it:result){
		if(f)putchar(' ');
		f=true;
		printf("%d",it);
	}
	puts("");
}
0