結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-06-21 18:37:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,793 bytes |
| コンパイル時間 | 1,560 ms |
| コンパイル使用メモリ | 75,060 KB |
| 実行使用メモリ | 816,160 KB |
| 最終ジャッジ日時 | 2024-10-11 18:31:19 |
| 合計ジャッジ時間 | 12,532 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | MLE * 1 -- * 17 |
ソースコード
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
#include <algorithm>
#define DBG(x) cerr << x << endl
using namespace std;
class Graph{
public:
vector<pair<int, int> >edges;
vector<int> cost_dp;
Graph(){
}
Graph(const Graph &g){
}
void setEdge(int id, int cost){
edges.push_back(make_pair(id, cost));
}
};
vector<Graph> g;
vector<int> d;
vector<int> result;
// queue((int city, int count_move));
queue<pair<int, int> > q;
void bfs(){
for(int i=0; i<g.size(); i++){
q.push(make_pair(i, 0));
}
while(!q.empty()){
int id = q.front().first;
int cost_id = q.front().second;
int cost = d[cost_id];
q.pop();
if(!g[id].cost_dp.empty() && g[id].cost_dp.back() == cost){
//if(binary_search(g[id].cost_dp.begin(), g[id].cost_dp.end(), cost)){
continue;
}
for(int i=0; i<g[id].edges.size(); i++){
if(g[id].edges[i].second == cost){
if(g[g[id].edges[i].first].cost_dp.empty() || g[g[id].edges[i].first].cost_dp.back() != cost){
g[g[id].edges[i].first].cost_dp.push_back(cost_id+1);
q.push(make_pair(g[id].edges[i].first, cost_id+1));
if(cost_id+1 == d.size()){
result.push_back(g[id].edges[i].first);
}
}
}
}
}
}
int main(){
int n,m,k;
cin >> n >> m >> k;
for(int i=0; i<=m; i++){
g.push_back(Graph());
}
for(int i=0; i<m; i++){
int a, b, c;
cin >> a >> b >> c;
g[a].setEdge(b, c);
g[b].setEdge(a, c);
}
for(int i=0; i<k; i++){
int tmp;
cin >> tmp;
d.push_back(tmp);
}
/*
for(int i=0; i<g.size(); i++){
for(int ii=0; ii<g[i].edges.size(); ii++){
DBG(g[i].edges[ii].first);
DBG(g[i].edges[ii].second);
DBG("");
}
}
*/
bfs();
cout << result.size() << endl;
for(int i=0; i<result.size(); i++){
cout << result[i] << " ";
}
cout << endl;
}