結果
問題 | No.92 逃走経路 |
ユーザー |
|
提出日時 | 2017-08-04 04:05:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 5,000 ms |
コード長 | 2,547 bytes |
コンパイル時間 | 1,807 ms |
コンパイル使用メモリ | 179,968 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 20:40:44 |
合計ジャッジ時間 | 2,595 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
// {{{ Templates#include <bits/stdc++.h>#define show(x) cerr << #x << " = " << x << endlusing namespace std;using ll = long long;using pii = pair<int, int>;using vi = vector<int>;template <typename T>ostream& operator<<(ostream& os, const vector<T>& v){os << "sz:" << v.size() << "\n[";for (const auto& p : v) {os << p << ",";}os << "]\n";return os;}template <typename S, typename T>ostream& operator<<(ostream& os, const pair<S, T>& p){os << "(" << p.first << "," << p.second<< ")";return os;}constexpr ll MOD = (ll)1e9 + 7LL;template <typename T>constexpr T INF = numeric_limits<T>::max() / 100;// }}}struct Edge {Edge() = default;Edge(int from, int to, ll cost) : from{from}, to{to}, cost{cost} {}int from;int to;ll cost;bool operator<(const Edge& e) const{return cost < e.cost;}};struct Graph {Graph(int n){edge.resize(n);}void addEdge(int from, int to, ll cost){edge[from].push_back(Edge{from, to, cost});edge[to].push_back(Edge{to, from, cost});}vector<vector<Edge>> edge;};int N, M, K;bool dfs(const Graph& g, const int pos, const int tim, const vector<ll>& d){if (tim == K) {return true;}const ll cost = d[tim];if (g.edge[pos].empty()) {return false;}auto it = lower_bound(g.edge[pos].begin(), g.edge[pos].end(), Edge{0, 0, cost});if (it == g.edge[pos].end()) {return false;} else {for (; it != g.edge[pos].end() and it->cost == cost; it++) {if (dfs(g, it->to, tim + 1, d)) {return true;}}return false;}}int main(){cin.tie(0);ios::sync_with_stdio(false);cin >> N >> M >> K;Graph g(N);for (int i = 0; i < M; i++) {int a, b;ll c;cin >> a >> b >> c;a--, b--;g.addEdge(a, b, c);}for (int i = 0; i < N; i++) {sort(g.edge[i].begin(), g.edge[i].end());}vector<ll> d(K);for (int i = 0; i < K; i++) {cin >> d[i];}reverse(d.begin(), d.end());vector<int> ans;for (int i = 0; i < N; i++) {if (dfs(g, i, 0, d)) {ans.push_back(i + 1);}}cout << ans.size() << endl;for (int i = 0; i < ans.size(); i++) {if (i != 0) {cout << " ";}cout << ans[i];}cout << endl;return 0;}