結果

問題 No.92 逃走経路
ユーザー chakkuchakku
提出日時 2015-10-17 18:40:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,428 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 74,668 KB
実行使用メモリ 13,340 KB
最終ジャッジ日時 2023-09-29 16:25:55
合計ジャッジ時間 2,437 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
13,132 KB
testcase_01 AC 6 ms
13,128 KB
testcase_02 AC 6 ms
13,108 KB
testcase_03 AC 5 ms
13,192 KB
testcase_04 AC 6 ms
13,320 KB
testcase_05 AC 8 ms
13,128 KB
testcase_06 AC 7 ms
13,160 KB
testcase_07 AC 7 ms
13,052 KB
testcase_08 AC 6 ms
13,116 KB
testcase_09 AC 5 ms
13,116 KB
testcase_10 AC 8 ms
13,084 KB
testcase_11 AC 8 ms
13,124 KB
testcase_12 AC 8 ms
13,268 KB
testcase_13 AC 6 ms
13,116 KB
testcase_14 AC 7 ms
13,340 KB
testcase_15 AC 8 ms
13,060 KB
testcase_16 AC 8 ms
13,060 KB
testcase_17 AC 9 ms
13,056 KB
testcase_18 AC 8 ms
13,060 KB
testcase_19 AC 8 ms
13,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
#include <climits>
#include <cmath>
using namespace std;

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,x,n) for(ll i=x;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<":"<<x<<endl
#define debug2(x,y) cout<<#x<<":"<<#y<<"=="<<x<<":"<<y<<endl
const int INF = INT_MAX / 3;
const int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };
#define MOD 1000000007
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;

int N, M, K;
int a[1001], b[1001], c[1001];
int d[1001];

//dp[i][j]:i回移動した後、街jに存在するか?
bool dp[10001][1001];

int main(){
	cin >> N >> M >> K;
	rep(i, M){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}
	rep(i, K) cin >> d[i];
	
	memset(dp, false, sizeof(dp));
	rep(i, 1001) dp[0][i] = true;
	rep(i, K){
		const int dist = d[i];
		const int before = i;
		const int after = i + 1;
		for (int j = 0; j < M; j++){
			if (dist == c[j]){
				if (dp[before][a[j]]) dp[after][b[j]] = true;
				if (dp[before][b[j]]) dp[after][a[j]] = true;
			}
		}
	}
	vi A;
	int ans = 0;
	rep(i, N){
		if (dp[K][i]){
			ans++;
			A.push_back(i + 1);
		}
	}
	cout << ans << endl;
	bool f = false;
	rep(i, ans){
		if (!f){
			cout << A[i];
			f = true;
		} else{
			cout << " " << A[i];
		}
	}
	cout << endl;
	return 0;
}
0