結果

問題 No.92 逃走経路
ユーザー not_522not_522
提出日時 2015-07-23 02:04:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 114 ms / 5,000 ms
コード長 3,232 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 161,560 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 21:29:38
合計ジャッジ時間 3,080 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 22 ms
4,380 KB
testcase_06 AC 14 ms
4,376 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 12 ms
4,384 KB
testcase_10 AC 114 ms
4,376 KB
testcase_11 AC 113 ms
4,376 KB
testcase_12 AC 59 ms
4,376 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 23 ms
4,376 KB
testcase_15 AC 38 ms
4,376 KB
testcase_16 AC 34 ms
4,380 KB
testcase_17 AC 43 ms
4,380 KB
testcase_18 AC 31 ms
4,380 KB
testcase_19 AC 22 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct Edge {
  typedef int CostType;
  const static int cost = 1;
  int from, to;
  Edge(int from, int to) : from(from), to(to) {};
};

template<typename Cost> struct WeightedEdge : public Edge {
  typedef Cost CostType;
  Cost cost;
  WeightedEdge(int from, int to, Cost cost = 0) : Edge(from, to), cost(cost) {}
};

template<typename Capacity> struct ResidualEdge : public Edge {
  typedef Capacity CapacityType;
  Capacity cap;
  int rev;
  ResidualEdge(int from, int to, Capacity cap) : Edge(from, to), cap(cap) {}
  ResidualEdge reverse() const {return ResidualEdge(to, from, 0);}
};

template<typename Capacity, typename Cost> struct WeightedResidualEdge : public ResidualEdge<Capacity> {
  Cost cost;
  WeightedResidualEdge(int from, int to, Capacity cap, Cost cost) : ResidualEdge<Capacity>(from, to, cap), cost(cost) {}
  WeightedResidualEdge reverse() const {return WeightedResidualEdge(this->to, this->from, 0, -cost);}
};

template<typename Edge> class Graph {
public:
  typedef Edge EdgeType;
  virtual int size() const = 0;
  template<typename... Args> void addEdge(Args...) {}
  template<typename... Args> void addUndirectedEdge(Args...) {}
  virtual vector<Edge> getEdges() const = 0;
  virtual vector<Edge> getEdges(int from) const = 0;
  virtual vector<Edge> getEdges(int from, int to) const = 0;
  virtual int getDegree(int v) const = 0;
};

template<typename Edge> class AdjacencyList : public Graph<Edge> {
protected:
  vector<vector<Edge>> graph;

public:
  AdjacencyList(int n) : graph(n) {}

  int size() const {
    return graph.size();
  }
  
  template<typename... Args> void addEdge(Args... args) {
    Edge edge(args...);
    graph[edge.from].emplace_back(edge);
  }

  template<typename... Args> void addUndirectedEdge(Args... args) {
    Edge edge(args...);
    addEdge(edge);
    swap(edge.from, edge.to);
    addEdge(edge);
  }

  vector<Edge> getEdges() const {
    vector<Edge> res;
    for (const auto& edges : graph) {
      res.insert(res.end(), edges.begin(), edges.end());
    }
    return res;
  }

  vector<Edge> getEdges(int from) const {
    return graph[from];
  }

  vector<Edge> getEdges(int from, int to) const {
    vector<Edge> res;
    for (const auto& edge : graph[from]) {
      if (edge.to == to) res.emplace_back(edge);
    }
    return res;
  }

  int getDegree(int v) const {
    return graph[v].size();
  }

  vector<Edge>& operator[](int v) {
    return graph[v];
  }
};

template<typename T> string to_string(const T& v) {
  string str;
  for (const auto& i : const_cast<T&>(v)) str += to_string(i) + " ";
  return str.substr(0, max(0, (int)str.size() - 1));
}

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  AdjacencyList<WeightedEdge<int>> graph(n + 1);
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    graph.addUndirectedEdge(a, b, c);
  }
  set<int> now, next;
  for (int i = 1; i <= n; ++i) now.insert(i);
  for (int i = 0; i < k; ++i) {
    int d;
    cin >> d;
    for (const auto& edge : graph.getEdges()) {
      if (now.count(edge.from) && d == edge.cost) next.insert(edge.to);
    }
    now = next;
    next.clear();
  }
  cout << now.size() << endl << to_string(now) << endl;
}
0