結果
| 問題 | 
                            No.92 逃走経路
                             | 
                    
| コンテスト | |
| ユーザー | 
                             chakku
                         | 
                    
| 提出日時 | 2015-10-17 18:40:31 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 9 ms / 5,000 ms | 
| コード長 | 1,428 bytes | 
| コンパイル時間 | 637 ms | 
| コンパイル使用メモリ | 75,340 KB | 
| 実行使用メモリ | 13,312 KB | 
| 最終ジャッジ日時 | 2024-07-22 10:31:27 | 
| 合計ジャッジ時間 | 1,610 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 18 | 
ソースコード
#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;
}
            
            
            
        
            
chakku