結果

問題 No.92 逃走経路
ユーザー めうめう🎒めうめう🎒
提出日時 2016-03-30 11:22:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 1,370 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 86,012 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 01:58:17
合計ジャッジ時間 1,697 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

vector<pair<int,int> > edge[110];
vector<int> ans;

int his[1010] = {};

int main() {
	int n,m,k;
	int a,b,c;
	cin >> n >> m >> k;
	for(int i = 0;i < m;i++){
		cin >> a >> b >> c;
		a--,b--;
		edge[a].push_back(make_pair(b,c));
		edge[b].push_back(make_pair(a,c));
	}
	for(int i = 0;i < k;i++){
		cin >> his[i];
	}
	bool memo[1010][101] = {};
	bool used[110] = {};
	for(int i = 0;i < n;i++){
		queue<pair<int,int> > que;
		que.push(make_pair(i,0));
		while(que.size()){
			int now = que.front().first,how = que.front().second;
			que.pop();
			if(how == k){
				if(used[now]) continue;
				used[now] = true;
				ans.push_back(now + 1);
				continue;
			}
			if(memo[how][now]) continue;
			memo[how][now] = true;
			for(int i = 0;i < edge[now].size();i++){
				if(his[how] != edge[now][i].second) {
					continue;
				}
				que.push(make_pair(edge[now][i].first,how + 1));
			}
		}
	}
	sort(ans.begin(),ans.end());
	cout << ans.size() << endl;
	for(int i = 0;i < ans.size();i++){
		if(i != ans.size() - 1) cout << ans[i] << " ";
		else cout << ans[i];
	}
	cout << endl;
	return 0;
}
0