結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-04 03:51:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,303 bytes |
| コンパイル時間 | 1,780 ms |
| コンパイル使用メモリ | 177,104 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 20:40:34 |
| 合計ジャッジ時間 | 2,524 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 7 |
ソースコード
// {{{ Templates
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using 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 {
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];
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);
}
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;
}