結果

問題 No.92 逃走経路
ユーザー TatamoTatamo
提出日時 2016-06-22 11:37:40
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,523 bytes
コンパイル時間 994 ms
コンパイル使用メモリ 83,072 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-01 23:39:04
合計ジャッジ時間 5,457 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

#define DBG(x) cerr << x << endl

using namespace std;

class Graph{
	public:
		vector<pair<int, int> >edges;
		Graph(){
		}
		void setEdge(int id, int cost){
			edges.push_back(make_pair(id, cost));
		}
};

vector<Graph> g;
vector<int> d;

map<int, Graph> search(){
	int count = 0;
	map<int, Graph> s;
	for(int i=1; i<=g.size(); i++){
		s.insert(map<int, Graph>::value_type(i, g[i]));
	}
	map<int, Graph> s_next;
	for(int c=0; c<d.size(); c++){
		for(auto itr = s.begin(); itr!=s.end(); itr++){
			for(int i=0; i < itr->second.edges.size(); i++){
				int cost = itr->second.edges[i].second;
				if(cost == d[count]){
					int index = itr->second.edges[i].first;
					s_next.insert(map<int, Graph>::value_type(index, g[index]));
				}
			}
		}
		s = s_next;
		s_next.clear();
		count += 1;
	}
	return s;
}

int main(){
	int n,m,k;
	cin >> n >> m >> k;

	for(int i=0; i<=m; i++){
		g.push_back(Graph());
	}
	for(int i=0; i<m; i++){
		int a, b, c;
		cin >> a >> b >> c;
		g[a].setEdge(b, c);
		g[b].setEdge(a, c);
	}

	for(int i=0; i<k; i++){
		int tmp;
		cin >> tmp;
		d.push_back(tmp);
	}

/*
	for(int i=0; i<g.size(); i++){
		for(int ii=0; ii<g[i].edges.size(); ii++){
			DBG(g[i].edges[ii].first);
			DBG(g[i].edges[ii].second);
			DBG("");
		}
	}
*/

	map<int, Graph> result = search();
	cout << result.size() << endl;
	for(auto itr=result.begin(); itr!=result.end(); itr++){
		cout << itr->first << " ";
	}
	cout << endl;

}
0