結果

問題 No.92 逃走経路
ユーザー kurenai3110kurenai3110
提出日時 2016-06-21 23:45:26
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,304 bytes
コンパイル時間 888 ms
コンパイル使用メモリ 79,284 KB
実行使用メモリ 453,868 KB
最終ジャッジ日時 2024-04-20 00:09:12
合計ジャッジ時間 13,101 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
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 <vector>
#include <algorithm>
#include <map>
#include <iterator>
using namespace std;

int solve(int n, int f, vector<pair<int, pair<int, int> > > &h);

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

	vector<pair<int, pair<int, int> > > h;
	h.resize(m);
	for (int i = 0; i<m; i++) {
		int a, b;
		long c;
		cin >> a >> b >> c;
		h[i] = make_pair(c,make_pair(a,b));
	}
	sort(h.begin(), h.end());

	long x;
	vector<int> nr;
	for (int i = 0; i < k; i++) {
		vector<int> r;

		cin >> x;
		for (int f = 0; f < m; f++) {
			if (h[f].first == x) {
				if (i == 0) {
					r.push_back(h[f].second.first);
					r.push_back(h[f].second.second);
				}
				else {
					int y;
					for (int j = 0; j < nr.size(); j++) {
						y = solve(nr[j], f, h);
						if (y) {
							r.push_back(y);
						}
					}
				}

			}
		}
		sort(r.begin(), r.end());
		unique(r.begin(), r.end());
		nr.clear();
		copy(r.begin(), r.end(), back_inserter(nr));
	}
	cout << nr.size() << endl;
	for (int i = 0; i<nr.size(); i++) {
		if (i) cout << " ";
		cout << nr[i];
	}
	cout << endl;

	return 0;
}

int solve(int n, int f, vector<pair<int, pair<int, int> > > &h) {
	if (n == h[f].second.first) {
		return h[f].second.second;
	}
	else if (n == h[f].second.second) {
		return h[f].second.first;
	}
	return 0;
}
0