結果

問題 No.92 逃走経路
ユーザー wunderkammer2wunderkammer2
提出日時 2020-01-02 00:23:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,830 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 114,768 KB
実行使用メモリ 818,008 KB
最終ジャッジ日時 2024-05-02 06:06:00
合計ジャッジ時間 7,730 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


class Pop
{
public:
	int end;
	int p;
	int count;

	Pop(int end, int p, int count)
	{
		this->end = end;
		this->p = p;
		this->count = count;
	}
};

int main()
{	
	int N, M, K;
	cin >> N >> M >> K;

	

	
	//nodes[i][j] := 町iから料金jの道路を通って行くことのできる町
	vector<map<int, vector<int>>> nodes(N);


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

		--a;
		--b;

		if (nodes[a].count(c) == 0)
		{
			nodes[a][c] = {};
		}

		nodes[a][c].push_back(b);

		if (nodes[b].count(c) == 0)
		{
			nodes[b][c] = {};
		}

		nodes[b][c].push_back(a);
	}

	vector<int> ds(K);
	rep(i, K)
	{
		cin >> ds[i];
	}


	//キューを使用して求める
	queue<Pop> q;

	//初期化
	rep(i, N)
	{
		//全ての町をセット
		q.emplace(i, i, 0);
	}

	//条件を満たす町を格納するためのset
	set<int> goals;

	while (!q.empty())
	{
		auto p = q.front(); q.pop();

		//K個の道路をたどることができた場合は、終了地点を答えに格納
		if (p.count == K)
		{
			goals.insert(p.p);
			continue;
		}
		
		//p.pに接続する料金がds[p.count]の道路に接続する町を、nodesから取得
		for (auto e : nodes[p.p][ds[p.count]])
		{
			q.emplace(p.end, e, p.count + 1);
		}
	}


	//結果表示
	cout << goals.size() << endl;

	for (auto g : goals)
	{
		cout << ++g << " ";
	}


	return 0;
}
0