結果

問題 No.92 逃走経路
ユーザー Zu_rinZu_rin
提出日時 2020-09-09 11:43:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 1,260 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 89,100 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 06:42:00
合計ジャッジ時間 1,929 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

void DFS(int n, int dep, vector<list<pp>> & d, vector<int> & t, set<int> &ans, vector<vector<int>> &dp) {
	if (dep == t.size()) {
		ans.insert(n);
		return;
	}
	if (dp[n][dep])
		return;
	dp[n][dep] = 1;
	int& x = t[dep];
	for (auto it = d[n].begin(); it != d[n].end(); it++) {
		if ((*it).first == x) {
			DFS((*it).second, dep + 1, d, t, ans, dp);
		}
	}
	return;
}

int main(void) {
	int num, m, k, i, a, b, c;
	cin >> num >> m >> k;
	vector<list<pp>> d(num + 1);
	vector<vector<int>> dp(num + 1, vector<int>(k, 0));
	vector<int> t(k);
	set<int> ans;
	rep(i, m) {
		cin >> a >> b >> c;
		d[a].push_back(pp(c, b));
		d[b].push_back(pp(c, a));
	}
	rep(i, k) {
		cin >> t[i];
	}
	for (i = 1; i <= num; i++) {
		DFS(i, 0, d, t, ans, dp);
	}
	cout << ans.size() << "\n";
	for (auto it = ans.begin(); it != ans.end(); it++) {
		cout << *it << " ";
	}
	printf("\n");
	return 0;
}
0