結果
| 問題 | No.92 逃走経路 |
| コンテスト | |
| ユーザー |
ldsyb
|
| 提出日時 | 2017-06-18 14:59:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 271 ms / 5,000 ms |
| コード長 | 1,135 bytes |
| 記録 | |
| コンパイル時間 | 960 ms |
| コンパイル使用メモリ | 87,500 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 19:59:33 |
| 合計ジャッジ時間 | 4,545 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
template <typename T>
string join(vector<T> v, string str){
stringstream ss;
for(int i = 0; i < v.size(); i++){
if(i) ss << str;
ss << v[i];
}
return ss.str();
}
struct edge{
int to, cost;
edge(int to, int cost){
this->to = to;
this->cost = cost;
}
};
int main(){
int n, m, k;
cin >> n >> m >> k;
vector<vector<edge>> e(n);
while(m--){
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
e[a].emplace_back(edge(b, c));
e[b].emplace_back(edge(a, c));
}
int d[k];
for(int i = 0; i < k; i++) cin >> d[i];
vector<vector<bool>> puni(k + 1, vector<bool>(n, false));
for(int i = 0; i < n; i++) puni[0][i] = true;
for(int i = 1; i <= k; i++) for(int j = 0; j < n; j++) if(puni[i - 1][j]) for(auto& ee:e[j]) if(ee.cost == d[i - 1]) puni[i][ee.to] = true;
for(int i = 0; i < k + 1; i++){
for(int j = 0; j < n; j++) cerr << puni[i][j] << ' ';
cerr << endl;
}
vector<int> ans;
for(int i = 0; i < n; i++) if(puni[k][i]) ans.emplace_back(i + 1);
cout << ans.size() << endl;
cout << join(ans, " ") << endl;
}
ldsyb