結果

問題 No.92 逃走経路
ユーザー ldsybldsyb
提出日時 2017-09-18 03:31:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 717 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 66,992 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 15:09:10
合計ジャッジ時間 1,181 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int main(){
	int n, m, k;
	cin >> n >> m >> k;
	int a[m], b[m], c[m], d[k];
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
	}
	for(int &i:d) cin >> i;
	bool dp[2][n];
	for(int i = 0; i < n; i++) dp[0][i] = true;
	for(int i = 0; i < k; i++){
		int now = i % 2, next = 1 ^ now;
		for(int j = 0; j < n; j++) dp[next][j] = false;
		for(int j = 0; j < m; j++){
			if(c[j] != d[i]) continue;
			dp[next][a[j]] |= dp[now][b[j]];
			dp[next][b[j]] |= dp[now][a[j]];
		}
	}
	int count = 0;
	for(int i = 0; i < n; i++) if(dp[k % 2][i]) count++;
	cout << count << endl;
	for(int i = 0; i < n; i++) if(dp[k % 2][i]) cout << i + 1 << ' ';
	cout << endl;
}
0