結果

問題 No.92 逃走経路
ユーザー ei1333333ei1333333
提出日時 2014-12-13 00:19:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 1,308 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 151,532 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 14:24:59
合計ジャッジ時間 2,408 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 18 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0