結果

問題 No.92 逃走経路
ユーザー hotpepsihotpepsi
提出日時 2015-08-26 01:43:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,029 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 77,952 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-25 18:28:38
合計ジャッジ時間 2,030 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using namespace std;

typedef vector<int> IntVec;
typedef map<int, IntVec> IIVMap;

int main(int argc, char *argv[])
{
	int N, M, K;
	cin >> N >> M >> K;
	IIVMap m[100];
	for (int i = 0; i < M; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		m[a - 1][c].push_back(b - 1);
		m[b - 1][c].push_back(a - 1);
	}
	int d[1000];
	for (int i = 0; i < K; ++i) {
		cin >> d[i];
	}
	int f[2][100] = {};
	for (int i = 0; i < N; ++i) {
		f[0][i] = 1;
	}
	for (int i = 0; i < K; ++i) {
		int prev = i & 1;
		int next = prev ^ 1;
		for (int j = 0; j < N; ++j) {
			f[next][j] = 0;
		}
		for (int j = 0; j < N; ++j) {
			if (f[prev][j]) {
				for (int a : m[j][d[i]]) {
					f[next][a] = 1;
				}
			}
		}
	}
	IntVec v;
	for (int i = 0; i < N; ++i) {
		if (f[K % 2][i]) {
			v.push_back(i + 1);
		}
	}
	cout << v.size() << endl;
	for (int i = 0; i < (int)v.size(); ++i) {
		if (i > 0) {
			cout << " ";
		}
		cout << v[i];
	}
	cout << endl;
	return 0;
}
0