File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ title : Trace(経路復元)
3+ documentation_of : ./marathon/trace.cpp
4+ ---
5+
6+ - ` add(value, id) `
7+ - 採用した値 ` value ` と直前の状態の識別子 ` id ` を与えて、状態を追加する
8+ - 追加した状態の識別子が返ってくる
9+ - ` get(id) `
10+ - 状態の識別子 ` id ` を与えると、初期状態からここに至るまでの経路を復元したものが返ってくる
Original file line number Diff line number Diff line change 1+ template <typename Tp>
2+ class Trace {
3+ public:
4+ Trace () = default ;
5+
6+ int add (const Tp& value, int parent) {
7+ log_.emplace_back (value, parent);
8+ return (int )log_.size () - 1 ;
9+ }
10+
11+ vector<Tp> get (int index) const {
12+ vector<Tp> result;
13+ while (index >= 0 ) {
14+ result.emplace_back (log_[index].first );
15+ index = log_[index].second ;
16+ }
17+ reverse (result.begin (), result.end ());
18+ return result;
19+ }
20+
21+ private:
22+ vector<pair<Tp, int >> log_;
23+ };
You can’t perform that action at this time.
0 commit comments