結果

問題 No.92 逃走経路
ユーザー wunderkammer2wunderkammer2
提出日時 2020-01-07 21:21:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,510 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 116,764 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 11:41:54
合計ジャッジ時間 2,013 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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>
// 追加1
#include <fstream>
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 false;
		if (this->b <= rhs.b) return false;

		return true;
	}
};

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