結果
| 問題 | No.92 逃走経路 |
| コンテスト | |
| ユーザー |
lapi
|
| 提出日時 | 2019-07-20 21:38:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 5,000 ms |
| コード長 | 1,380 bytes |
| 記録 | |
| コンパイル時間 | 2,616 ms |
| コンパイル使用メモリ | 110,120 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 14:55:05 |
| 合計ジャッジ時間 | 2,643 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
bool dp[1009][109]; // dp[i][j] : i回目の移動後に町jにいる可能性があるかどうか
vector<int> G[109][109];
int cost[1009];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M, K; cin >> N >> M >> K;
for (int i = 0; i < M; i++) {
int tmp1, tmp2, d; cin >> tmp1 >> tmp2 >> d;
G[tmp1][tmp2].push_back(d);
G[tmp2][tmp1].push_back(d);
}
for (int i = 1; i <= K; i++) cin >> cost[i];
for (int i = 1; i <= N; i++) dp[0][i] = true;
for (int i = 1; i <= K; i++) {
for (int j = 1; j <= N; j++) {
if (dp[i - 1][j]) { // 直前に犯人が町jにいる可能性があるとしたら
for (int k = 1; k <= N; k++) {
for (int p = 0; p < G[j][k].size(); p++) {
if (G[j][k][p] == cost[i]) dp[i][k] = true;
}
}
}
}
}
int ans = 0;
for (int i = 1; i <= N; i++) {
if (dp[K][i]) ans++;
}
cout << ans << endl;
for (int i = 1; i <= N; i++) {
if (dp[K][i]) cout << i << " ";
}
cout << endl;
return 0;
}
lapi