結果
問題 |
No.92 逃走経路
|
ユーザー |
![]() |
提出日時 | 2017-09-18 03:08:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 980 bytes |
コンパイル時間 | 854 ms |
コンパイル使用メモリ | 81,156 KB |
実行使用メモリ | 270,824 KB |
最終ジャッジ日時 | 2024-11-08 02:09:06 |
合計ジャッジ時間 | 13,319 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 2 |
other | TLE * 1 -- * 17 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct edge{ int to, cost; edge(int to, int cost){ this->to = to; this->cost = cost; } }; void dfs(vector<vector<edge>> &v, vector<int> &d, vector<int> &ans, int k, int now, int count = 0){ if(count == k){ ans.emplace_back(now + 1); return; } for(edge &e:v[now]){ if(e.cost == d[count]){ dfs(v, d, ans, k, e.to, count + 1); } } } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; vector<vector<edge>> v(n); while(m--){ int a, b, c; cin >> a >> b >> c; a--; b--; v[a].emplace_back(edge(b, c)); v[b].emplace_back(edge(a, c)); } vector<int> d(k); for(int &x:d) cin >> x; vector<int> ans; for(int i = 0; i < n; i++){ dfs(v, d, ans, k, i); } sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); cout << ans.size() << endl; for(int x:ans) cout << x << ' '; cout << endl; return 0; }