結果

問題 No.92 逃走経路
ユーザー kurenai3110kurenai3110
提出日時 2016-06-22 01:09:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 117 ms / 5,000 ms
コード長 1,408 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 85,184 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 00:13:14
合計ジャッジ時間 2,118 ms
ジャッジサーバーID
(参考情報)
judge5 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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++) {
		cin >> x;
		size_t f;
		f = distance(c1.begin(), lower_bound(c1.begin(), c1.end(), x));
		int s = nr.size();
		while (f<m&&c1[f] == x) {
			if (i == 0) {
				nr.push_back(h[f].second.first);
				nr.push_back(h[f].second.second);
			}
			else {
				int y;
				for (int j = 0; j <s; j++) {
					y = solve(nr[j], f, h);
					if (y) {
						nr.push_back(y);
					}
				}
			}
			f++;
		}
		if(i)nr.erase(nr.begin(), nr.begin() + s);
		sort(nr.begin(), nr.end());
		nr.erase(unique(nr.begin(), nr.end()),nr.end());

	}
	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