結果

問題 No.92 逃走経路
ユーザー matsukin1111matsukin1111
提出日時 2019-04-04 21:26:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,364 bytes
コンパイル時間 1,241 ms
コンパイル使用メモリ 92,112 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 01:58:50
合計ジャッジ時間 3,980 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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