結果

問題 No.92 逃走経路
ユーザー data9824data9824
提出日時 2015-06-02 03:52:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 991 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 61,368 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 18:26:09
合計ジャッジ時間 1,732 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 14 ms
4,376 KB
testcase_19 AC 13 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<int> a(m), b(m), c(m);
	for (int i = 0; i < m; ++i) {
		cin >> a[i] >> b[i] >> c[i];
	}
	vector<int> d(k);
	for (int i = 0; i < k; ++i) {
		cin >> d[i];
	}
	static bool exists[101][1000] = { false }; // [city][log]
	for (int i = 0; i < m; ++i) {
		bool e = (c[i] == d[0]);
		exists[a[i]][0] |= e;
		exists[b[i]][0] |= e;
	}
	for (int j = 1; j < k; ++j) {
		for (int i = 0; i < m; ++i) {
			if (exists[a[i]][j - 1]) {
				bool e = (c[i] == d[j]);
				exists[b[i]][j] |= e;
			}
			if (exists[b[i]][j - 1]) {
				bool e = (c[i] == d[j]);
				exists[a[i]][j] |= e;
			}
		}
	}
	vector<int> cityNumbers;
	for (int i = 1; i <= n; ++i) {
		if (exists[i][k - 1]) {
			cityNumbers.push_back(i);
		}
	}
	cout << cityNumbers.size() << endl;
	for (size_t i = 0; i < cityNumbers.size(); ++i) {
		if (i > 0) {
			cout << " ";
		}
		cout << cityNumbers[i];
	}
	cout << endl;
	return 0;
}
0