結果

問題 No.92 逃走経路
ユーザー wunderkammer2wunderkammer2
提出日時 2020-01-07 21:32:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,517 bytes
コンパイル時間 1,125 ms
コンパイル使用メモリ 113,976 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 11:44:12
合計ジャッジ時間 1,891 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 Edge
{
public:
	int a;
	int b;

	Edge(int a, int b)
	{
		this->a = a;
		this->b = b;
	}

	bool operator<(const Edge& rhs) const
	{ 
		if (this->a <  rhs.a) return true;

		if (this->a > rhs.a) return false;

		if (this->b < rhs.b) return true;

		return false;
	}
};

int main()
{


	int N, M, K;
	cin >> N >> M >> K;

	map<int, set<Edge>> edges;
	rep(i, M)
	{
		int a, b, c;
		cin >> a >> b >> c;

		--a;
		--b;

		edges[c].emplace(a, b);
	}

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


	//動的計画法で計算
	//グラフが双方向なので、2次元グラフで計算すること
	vector<vector<int>> dp(K + 1, vector<int>(N, 0));

	rep(i, K)
	{
		for (auto e : edges[ds[i]])
		{
			if(dp[i][e.b] == i)
				dp[i + 1][e.a] = i + 1;
			if(dp[i][e.a] == i)
				dp[i + 1][e.b] = i + 1;
		}
	}


	//答えを確認
	set<int> goals;

	rep(i, N)
	{
		if (dp[K][i] > 0)
		{
			goals.insert(i + 1);
		}
	}


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

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

	return 0;
}
0