結果

問題 No.92 逃走経路
ユーザー kurenai3110kurenai3110
提出日時 2016-06-22 00:35:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,410 bytes
コンパイル時間 909 ms
コンパイル使用メモリ 85,028 KB
実行使用メモリ 447,936 KB
最終ジャッジ日時 2024-04-20 00:13:12
合計ジャッジ時間 13,316 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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<long, pair<int, int> > > &h);

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

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

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

		cin >> x;
		size_t f;
		f = distance(c1.begin(), lower_bound(c1.begin(), c1.end(), x));
		while (f<m&&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);
					}
				}
			}
			f++;
		}
		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<long, 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