結果
| 問題 | No.92 逃走経路 |
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2014-12-13 00:19:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 5,000 ms |
| コード長 | 1,308 bytes |
| 記録 | |
| コンパイル時間 | 1,332 ms |
| コンパイル使用メモリ | 167,464 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-11 21:03:01 |
| 合計ジャッジ時間 | 2,119 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
struct edge{
int to, cost;
};
vector< int > visit;
typedef vector< vector< edge > > Graph;
void add_edge(Graph& info, int u, int v, int cost, bool flag = true){
info[u].push_back( (edge){ v, cost});
if(flag) info[v].push_back( (edge){ u, cost});
}
bool check(const Graph& graph, const vector< int >& d, int pos, int idx){
if(pos == -1) return true;
for(int i = 0; i < graph[idx].size(); i++){
if(graph[idx][i].cost == d[pos] && check(graph, d, pos - 1, graph[idx][i].to)) return true;
}
return false;
}
int main(){
int N, M, K;
cin >> N >> M >> K;
Graph graph(N);
for(int i = 0; i < M; i++){
int a, b, c;
cin >> a >> b >> c;
add_edge( graph, a - 1, b - 1, c);
}
vector< int > d(K);
for(int i = 0; i < K; i++){
cin >> d[i];
}
for(int i = 0; i < N; i++){
for(int j = 0; j < graph[i].size(); j++){
if(graph[i][j].cost == d[K - 1] && check(graph, d, K - 2, graph[i][j].to)){
visit.push_back(i + 1);
break;
}
}
}
cout << visit.size() << endl;
for(vector< int >::const_iterator it = visit.begin(); it != visit.end(); it++){
cout << (it == visit.begin() ? "": " ") << *it;
}
cout << endl;
}
ei1333333