結果

問題 No.92 逃走経路
ユーザー matsukin1111
提出日時 2019-04-04 21:26:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,364 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 98,620 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 06:32:45
合計ジャッジ時間 4,705 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 WA * 4 RE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #


#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };


int n, m, k;
vector<vector<int>>e[1010];
vector<int>d;

int dfs(int now,int num) {
	if (num == k)return 1;

	int next = d[num];
	fore(x,e[next]) {
		if (x[1] == now) {
			if (dfs(x[0], num + 1))return 1;
		}
	}
	return 0;
}

int main(){
	cin >> n >> m >> k;

	rep(i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c; 

		e[c].pb({a,b});
		e[c].pb({b,a});
	}

	rep(i, 0, k) {
		int D;
		cin >> D;
		d.pb(D);
	}
	reverse(all(d));

	int ans = 0;
	vector<int>town;
	fore(x,e[d[0]]) {
		if (dfs(x[0], 1)) {
			ans++;
			town.pb(x[1]);
		}
	}
	cout << ans << endl;
	sort(all(town));
	rep(i, 0, ans) {
		if (i)cout << " ";
		cout << town[i];
	}
	cout << endl;

	return 0;
}
0