From 495fe3d99e5a1a8a86a92be1065a028b31901c2b Mon Sep 17 00:00:00 2001 From: Victor Baldin Date: Tue, 9 Dec 2025 14:16:43 +0000 Subject: [PATCH 1/6] c++ --- include/graphs/graph.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/graphs/graph.hh b/include/graphs/graph.hh index 709cc36..a5e09c0 100644 --- a/include/graphs/graph.hh +++ b/include/graphs/graph.hh @@ -18,7 +18,7 @@ class Graph final { vertices_.insert(a); } - return adj_list_.insert({v, adj}).second; + return adj_list_.emplace(v, adj).second; } void dump() const { @@ -33,8 +33,8 @@ class Graph final { vd.reserve(adj_list_.size()); for (const auto& v : vertices_) { auto d = add_vertex(g); - put(vertex_name, g, d, std::to_string(v)); - vd.insert({v, d}); + put(vertex_name, g, d, v); + vd.emplace(v, d); } for (auto& [v, adj] : adj_list_) { From 7a022006dd1602b1a5ea5c6eed136bb84d5fddf7 Mon Sep 17 00:00:00 2001 From: Victor Baldin Date: Tue, 9 Dec 2025 14:41:45 +0000 Subject: [PATCH 2/6] fix tests + add end node --- include/graphs/graph.hh | 24 +++++++++++++++++++----- src/main.cc | 8 ++++---- tests/out/1.dot | 15 +++++++++------ tests/run_tests.py | 4 ++-- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/graphs/graph.hh b/include/graphs/graph.hh index a5e09c0..7b6023f 100644 --- a/include/graphs/graph.hh +++ b/include/graphs/graph.hh @@ -12,13 +12,27 @@ namespace graph { template class Graph final { public: + Graph(const T& start = T(), const T& end = T()) + : end_(end), adj_list_{{end_, std::vector{}}} {} + bool insert(const T& v, const std::vector& adj) { - vertices_.insert(v); for (const auto& a : adj) { - vertices_.insert(a); + auto it = adj_list_.find(a); + if (it == adj_list_.end()) { + adj_list_.emplace( + a, std::vector{end_}); // speculatively mark as end node + } } - return adj_list_.emplace(v, adj).second; + auto [it, ins] = adj_list_.emplace(v, adj); + if (!ins) { + if (it->second == std::vector{end_}) { + it->second = adj; + } else { + return false; + } + } + return true; } void dump() const { @@ -31,7 +45,7 @@ class Graph final { std::unordered_map vd; vd.reserve(adj_list_.size()); - for (const auto& v : vertices_) { + for (const auto& [v, _] : adj_list_) { auto d = add_vertex(g); put(vertex_name, g, d, v); vd.emplace(v, d); @@ -47,7 +61,7 @@ class Graph final { } private: + T end_; std::unordered_map> adj_list_; - std::unordered_set vertices_; }; } // namespace graph diff --git a/src/main.cc b/src/main.cc index bb0efdf..e3589cf 100644 --- a/src/main.cc +++ b/src/main.cc @@ -35,7 +35,7 @@ int main(int argc, char** argv) try { return 0; } - graph::Graph g; + graph::Graph g("Start", "End"); std::string line; while (std::getline(std::cin, line)) { @@ -44,11 +44,11 @@ int main(int argc, char** argv) try { } std::istringstream ss(line); - std::size_t u; + std::string u; ss >> u; - std::vector adj; - std::size_t v; + std::vector adj; + std::string v; while (ss >> v) { adj.push_back(v); } diff --git a/tests/out/1.dot b/tests/out/1.dot index 38580c9..fcd57cf 100644 --- a/tests/out/1.dot +++ b/tests/out/1.dot @@ -2,11 +2,14 @@ digraph G { 0[label=9]; 1[label=2]; 2[label=7]; -3[label=5]; -4[label=3]; +3[label=3]; +4[label=5]; +5[label=End]; +0->5 ; +1->5 ; 2->0 ; -3->0 ; -4->3 ; -4->2 ; -4->1 ; +3->4 ; +3->2 ; +3->1 ; +4->0 ; } diff --git a/tests/run_tests.py b/tests/run_tests.py index 35e0c44..cea1921 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -4,7 +4,7 @@ import glob CURRENT_PATH = os.path.abspath(os.path.dirname(__file__)) -PATH_TO_INPUT = [CURRENT_PATH + '/in/'] +PATH_TO_INPUT = os.path.join(CURRENT_PATH, "in") def get_dot_file_path(input_path): @@ -45,7 +45,7 @@ def test(executable): raise RuntimeError("End-to-end test failed\n") -if __name__ == "main": +if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--executable', help='Executable to test') args = parser.parse_args() From a1f526f24a5717c33a1a0176948c8152e210d08d Mon Sep 17 00:00:00 2001 From: Victor Baldin Date: Tue, 9 Dec 2025 14:54:43 +0000 Subject: [PATCH 3/6] add start node --- include/graphs/graph.hh | 24 +++++++++++++++++++++++- tests/out/1.dot | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/graphs/graph.hh b/include/graphs/graph.hh index 7b6023f..86948c9 100644 --- a/include/graphs/graph.hh +++ b/include/graphs/graph.hh @@ -13,7 +13,9 @@ template class Graph final { public: Graph(const T& start = T(), const T& end = T()) - : end_(end), adj_list_{{end_, std::vector{}}} {} + : start_(start), + end_(end), + adj_list_{{start, std::vector{}}, {end_, std::vector{}}} {} bool insert(const T& v, const std::vector& adj) { for (const auto& a : adj) { @@ -22,6 +24,11 @@ class Graph final { adj_list_.emplace( a, std::vector{end_}); // speculatively mark as end node } + ++in_deg_[a]; + } + + if (in_deg_.find(v) == in_deg_.end()) { + in_deg_.emplace(v, 0); } auto [it, ins] = adj_list_.emplace(v, adj); @@ -32,6 +39,8 @@ class Graph final { return false; } } + + linkToStart(); return true; } @@ -61,7 +70,20 @@ class Graph final { } private: + T start_; T end_; std::unordered_map> adj_list_; + std::unordered_map in_deg_; + + void linkToStart() { + auto& start_nodes = adj_list_[start_]; + start_nodes.clear(); + + for (const auto& [v, c] : in_deg_) { + if (c == 0) { + start_nodes.push_back(v); + } + } + } }; } // namespace graph diff --git a/tests/out/1.dot b/tests/out/1.dot index fcd57cf..0cf8e08 100644 --- a/tests/out/1.dot +++ b/tests/out/1.dot @@ -5,6 +5,7 @@ digraph G { 3[label=3]; 4[label=5]; 5[label=End]; +6[label=Start]; 0->5 ; 1->5 ; 2->0 ; @@ -12,4 +13,5 @@ digraph G { 3->2 ; 3->1 ; 4->0 ; +6->3 ; } From f41fda9392bf64c37bf90508801dce7f4e9b1ea6 Mon Sep 17 00:00:00 2001 From: Victor Baldin Date: Tue, 9 Dec 2025 15:50:07 +0000 Subject: [PATCH 4/6] add more tests --- include/graphs/graph.hh | 5 +- tests/in/2.in | 24 ++ tests/in/3.in | 7 + tests/in/4.in | 19 + tests/in/5.in | 137 +++++++ tests/in/6.in | 241 ++++++++++++ tests/out/2.dot | 71 ++++ tests/out/3.dot | 42 ++ tests/out/4.dot | 54 +++ tests/out/5.dot | 527 +++++++++++++++++++++++++ tests/out/6.dot | 836 ++++++++++++++++++++++++++++++++++++++++ 11 files changed, 1961 insertions(+), 2 deletions(-) create mode 100644 tests/in/2.in create mode 100644 tests/in/3.in create mode 100644 tests/in/4.in create mode 100644 tests/in/5.in create mode 100644 tests/in/6.in create mode 100644 tests/out/2.dot create mode 100644 tests/out/3.dot create mode 100644 tests/out/4.dot create mode 100644 tests/out/5.dot create mode 100644 tests/out/6.dot diff --git a/include/graphs/graph.hh b/include/graphs/graph.hh index 86948c9..99086cd 100644 --- a/include/graphs/graph.hh +++ b/include/graphs/graph.hh @@ -31,9 +31,10 @@ class Graph final { in_deg_.emplace(v, 0); } - auto [it, ins] = adj_list_.emplace(v, adj); + auto [it, ins] = + adj_list_.emplace(v, adj.empty() ? std::vector{end_} : adj); if (!ins) { - if (it->second == std::vector{end_}) { + if (it->second == std::vector{end_} && !adj.empty()) { it->second = adj; } else { return false; diff --git a/tests/in/2.in b/tests/in/2.in new file mode 100644 index 0000000..bb886ce --- /dev/null +++ b/tests/in/2.in @@ -0,0 +1,24 @@ +1 2 6 +2 3 7 +3 4 8 +4 5 9 +5 10 +6 7 11 +7 8 12 +8 9 13 +9 10 14 +10 15 +11 12 16 +12 13 17 +13 14 18 +14 15 19 +15 20 +16 17 21 +17 18 22 +18 19 23 +19 20 24 +20 25 +21 22 +22 23 +23 24 +24 25 diff --git a/tests/in/3.in b/tests/in/3.in new file mode 100644 index 0000000..f8a828b --- /dev/null +++ b/tests/in/3.in @@ -0,0 +1,7 @@ +1 2 3 +2 4 5 +3 6 7 +4 8 9 +5 10 11 +6 12 13 +7 14 15 diff --git a/tests/in/4.in b/tests/in/4.in new file mode 100644 index 0000000..af1036e --- /dev/null +++ b/tests/in/4.in @@ -0,0 +1,19 @@ +1 2 11 +2 3 12 +3 4 13 +4 5 14 +5 6 15 +6 7 16 +7 8 17 +8 9 18 +9 10 19 +10 20 +11 12 +12 13 +13 14 +14 15 +15 16 +16 17 +17 18 +18 19 +19 20 diff --git a/tests/in/5.in b/tests/in/5.in new file mode 100644 index 0000000..6de28de --- /dev/null +++ b/tests/in/5.in @@ -0,0 +1,137 @@ +1 2 3 4 +2 5 6 7 +3 8 9 10 +4 11 12 13 +5 14 15 16 +6 15 16 17 +7 17 18 19 +8 19 20 21 +9 20 21 22 +10 22 23 24 +11 24 25 26 +12 25 26 27 +13 27 28 +14 29 30 31 +15 30 31 32 +16 32 33 34 +17 33 34 35 +18 35 36 37 +19 36 37 38 +20 37 38 39 +21 38 39 40 +22 39 40 41 +23 40 41 42 +24 41 42 43 +25 42 43 44 +26 43 44 45 +27 44 45 46 +28 46 47 48 +29 47 48 49 +30 48 49 50 +31 49 50 51 +32 50 51 52 +33 51 52 53 +34 52 53 54 +35 53 54 55 +36 54 55 56 +37 55 56 57 +38 56 57 58 +39 57 58 59 +40 58 59 60 +41 59 60 61 +42 60 61 62 +43 61 62 63 +44 62 63 64 +45 63 64 65 +46 64 65 66 +47 65 66 67 +48 66 67 68 +49 67 68 69 +50 68 69 70 +51 69 70 71 +52 70 71 72 +53 71 72 73 +54 72 73 74 +55 73 74 75 +56 74 75 76 +57 75 76 77 +58 76 77 78 +59 77 78 79 +60 78 79 80 +61 79 80 81 +62 80 81 82 +63 81 82 83 +64 82 83 84 +65 83 84 85 +66 84 85 86 +67 85 86 87 +68 86 87 88 +69 87 88 89 +70 88 89 90 +71 89 90 91 +72 90 91 92 +73 91 92 93 +74 92 93 94 +75 93 94 95 +76 94 95 96 +77 95 96 97 +78 96 97 98 +79 97 98 99 +80 98 99 100 +81 99 100 101 +82 100 101 102 +83 101 102 103 +84 102 103 104 +85 103 104 105 +86 104 105 106 +87 105 106 107 +88 106 107 108 +89 107 108 109 +90 108 109 110 +91 109 110 111 +92 110 111 112 +93 111 112 113 +94 112 113 114 +95 113 114 115 +96 114 115 116 +97 115 116 117 +98 116 117 118 +99 117 118 119 +100 118 119 120 +101 119 120 121 +102 120 121 122 +103 121 122 123 +104 122 123 124 +105 123 124 125 +106 124 125 126 +107 125 126 127 +108 126 127 128 +109 127 128 129 +110 128 129 130 +111 129 130 131 +112 130 131 132 +113 131 132 133 +114 132 133 134 +115 133 134 135 +116 134 135 136 +117 135 136 137 +118 136 137 +119 136 137 +120 136 137 +121 136 137 +122 136 137 +123 136 137 +124 136 137 +125 136 137 +126 136 137 +127 136 137 +128 136 137 +129 136 137 +130 136 137 +131 136 137 +132 136 137 +133 137 +134 +135 +136 +137 diff --git a/tests/in/6.in b/tests/in/6.in new file mode 100644 index 0000000..4fe892c --- /dev/null +++ b/tests/in/6.in @@ -0,0 +1,241 @@ +1 4 5 6 +2 6 7 8 +3 8 9 +4 10 11 12 +5 12 13 14 +6 14 15 16 +7 16 17 18 +8 18 19 20 +9 20 21 +10 22 23 +11 24 25 26 +12 25 26 27 +13 27 28 +14 29 30 31 +15 30 31 32 +16 32 33 34 +17 33 34 35 +18 35 36 37 +19 36 37 38 +20 37 38 39 +21 38 39 40 +22 39 40 41 +23 40 41 42 +24 41 42 43 +25 42 43 44 +26 43 44 45 +27 44 45 46 +28 46 47 48 +29 47 48 49 +30 48 49 50 +31 49 50 51 +32 50 51 52 +33 51 52 53 +34 52 53 54 +35 53 54 55 +36 54 55 56 +37 55 56 57 +38 56 57 58 +39 57 58 59 +40 58 59 60 +41 59 60 61 +42 60 61 62 +43 61 62 63 +44 62 63 64 +45 63 64 65 +46 64 65 66 +47 65 66 67 +48 66 67 68 +49 67 68 69 +50 68 69 70 +51 69 70 71 +52 70 71 72 +53 71 72 73 +54 72 73 74 +55 73 74 75 +56 74 75 76 +57 75 76 77 +58 76 77 78 +59 77 78 79 +60 78 79 80 +61 79 80 81 +62 80 81 82 +63 81 82 83 +64 82 83 84 +65 83 84 85 +66 84 85 86 +67 85 86 87 +68 86 87 88 +69 87 88 89 +70 88 89 90 +71 89 90 91 +72 90 91 92 +73 91 92 93 +74 92 93 94 +75 93 94 95 +76 94 95 96 +77 95 96 97 +78 96 97 98 +79 97 98 99 +80 98 99 100 +81 99 100 101 +82 100 101 102 +83 101 102 103 +84 102 103 104 +85 103 104 105 +86 104 105 106 +87 105 106 107 +88 106 107 108 +89 107 108 109 +90 108 109 110 +91 109 110 111 +92 110 111 112 +93 111 112 113 +94 112 113 114 +95 113 114 115 +96 114 115 116 +97 115 116 117 +98 116 117 118 +99 117 118 119 +100 118 119 120 +101 119 120 121 +102 120 121 122 +103 121 122 123 +104 122 123 124 +105 123 124 125 +106 124 125 126 +107 125 126 127 +108 126 127 128 +109 127 128 129 +110 128 129 130 +111 129 130 131 +112 130 131 132 +113 131 132 133 +114 132 133 134 +115 133 134 135 +116 134 135 136 +117 135 136 137 +118 136 137 +119 136 137 +120 136 137 +121 136 137 +122 136 137 +123 136 137 +124 136 137 +125 136 137 +126 136 137 +127 136 137 +128 136 137 +129 136 137 +130 136 137 +131 136 137 +132 136 137 +133 137 +134 +135 +136 +137 +138 139 140 +139 141 142 +140 142 143 +141 143 144 +142 144 145 +143 145 146 +144 146 147 +145 147 148 +146 148 149 +147 149 150 +148 150 151 +149 151 152 +150 152 153 +151 153 154 +152 154 155 +153 155 156 +154 156 157 +155 157 158 +156 158 159 +157 159 160 +158 160 161 +159 161 162 +160 162 163 +161 163 164 +162 164 165 +163 165 166 +164 166 167 +165 167 168 +166 168 169 +167 169 170 +168 170 171 +169 171 172 +170 172 173 +171 173 174 +172 174 175 +173 175 176 +174 176 177 +175 177 178 +176 178 179 +177 179 180 +178 180 181 +179 181 182 +180 182 183 +181 183 184 +182 184 185 +183 185 186 +184 186 187 +185 187 188 +186 188 189 +187 189 190 +188 190 191 +189 191 192 +190 192 193 +191 193 194 +192 194 195 +193 195 196 +194 196 197 +195 197 198 +196 198 199 +197 199 200 +198 200 201 +199 201 202 +200 202 203 +201 203 204 +202 204 205 +203 205 206 +204 206 207 +205 207 208 +206 208 209 +207 209 210 +208 210 211 +209 211 212 +210 212 213 +211 213 214 +212 214 215 +213 215 216 +214 216 217 +215 217 218 +216 218 219 +217 219 220 +218 220 221 +219 221 222 +220 222 223 +221 223 224 +222 224 225 +223 225 226 +224 226 227 +225 227 228 +226 228 229 +227 229 230 +228 230 231 +229 231 232 +230 232 233 +231 233 234 +232 234 235 +233 235 236 +234 +235 +236 +237 +238 +239 +240 +241 diff --git a/tests/out/2.dot b/tests/out/2.dot new file mode 100644 index 0000000..7c5dc78 --- /dev/null +++ b/tests/out/2.dot @@ -0,0 +1,71 @@ +digraph G { +0[label=25]; +1[label=24]; +2[label=23]; +3[label=21]; +4[label=20]; +5[label=14]; +6[label=12]; +7[label=15]; +8[label=13]; +9[label=Start]; +10[label=10]; +11[label=End]; +12[label=2]; +13[label=19]; +14[label=6]; +15[label=16]; +16[label=3]; +17[label=5]; +18[label=17]; +19[label=7]; +20[label=4]; +21[label=8]; +22[label=22]; +23[label=1]; +24[label=9]; +25[label=18]; +26[label=11]; +0->11 ; +1->0 ; +2->1 ; +3->22 ; +4->0 ; +5->7 ; +5->13 ; +6->8 ; +6->18 ; +7->4 ; +8->5 ; +8->25 ; +9->23 ; +10->7 ; +12->16 ; +12->19 ; +13->4 ; +13->1 ; +14->19 ; +14->26 ; +15->18 ; +15->3 ; +16->20 ; +16->21 ; +17->10 ; +18->25 ; +18->22 ; +19->21 ; +19->6 ; +20->17 ; +20->24 ; +21->24 ; +21->8 ; +22->2 ; +23->12 ; +23->14 ; +24->10 ; +24->5 ; +25->13 ; +25->2 ; +26->6 ; +26->15 ; +} diff --git a/tests/out/3.dot b/tests/out/3.dot new file mode 100644 index 0000000..0bc0e0a --- /dev/null +++ b/tests/out/3.dot @@ -0,0 +1,42 @@ +digraph G { +0[label=14]; +1[label=12]; +2[label=15]; +3[label=13]; +4[label=Start]; +5[label=10]; +6[label=End]; +7[label=2]; +8[label=3]; +9[label=5]; +10[label=4]; +11[label=6]; +12[label=7]; +13[label=8]; +14[label=1]; +15[label=9]; +16[label=11]; +0->6 ; +1->6 ; +2->6 ; +3->6 ; +4->14 ; +5->6 ; +7->10 ; +7->9 ; +8->11 ; +8->12 ; +9->5 ; +9->16 ; +10->13 ; +10->15 ; +11->1 ; +11->3 ; +12->0 ; +12->2 ; +13->6 ; +14->7 ; +14->8 ; +15->6 ; +16->6 ; +} diff --git a/tests/out/4.dot b/tests/out/4.dot new file mode 100644 index 0000000..0fed8e7 --- /dev/null +++ b/tests/out/4.dot @@ -0,0 +1,54 @@ +digraph G { +0[label=20]; +1[label=10]; +2[label=8]; +3[label=17]; +4[label=7]; +5[label=End]; +6[label=2]; +7[label=18]; +8[label=11]; +9[label=9]; +10[label=1]; +11[label=16]; +12[label=3]; +13[label=5]; +14[label=12]; +15[label=4]; +16[label=Start]; +17[label=15]; +18[label=13]; +19[label=14]; +20[label=19]; +21[label=6]; +0->5 ; +1->0 ; +2->9 ; +2->7 ; +3->7 ; +4->2 ; +4->3 ; +6->12 ; +6->14 ; +7->20 ; +8->14 ; +9->1 ; +9->20 ; +10->6 ; +10->8 ; +11->3 ; +12->15 ; +12->18 ; +13->21 ; +13->17 ; +14->18 ; +15->13 ; +15->19 ; +16->10 ; +17->11 ; +18->19 ; +19->17 ; +20->0 ; +21->4 ; +21->11 ; +} diff --git a/tests/out/5.dot b/tests/out/5.dot new file mode 100644 index 0000000..bba26fc --- /dev/null +++ b/tests/out/5.dot @@ -0,0 +1,527 @@ +digraph G { +0[label=137]; +1[label=134]; +2[label=132]; +3[label=130]; +4[label=129]; +5[label=133]; +6[label=127]; +7[label=126]; +8[label=54]; +9[label=50]; +10[label=48]; +11[label=46]; +12[label=37]; +13[label=96]; +14[label=49]; +15[label=53]; +16[label=61]; +17[label=103]; +18[label=111]; +19[label=55]; +20[label=62]; +21[label=31]; +22[label=57]; +23[label=56]; +24[label=79]; +25[label=29]; +26[label=99]; +27[label=41]; +28[label=28]; +29[label=39]; +30[label=11]; +31[label=90]; +32[label=18]; +33[label=9]; +34[label=36]; +35[label=108]; +36[label=76]; +37[label=22]; +38[label=85]; +39[label=8]; +40[label=35]; +41[label=40]; +42[label=67]; +43[label=38]; +44[label=17]; +45[label=95]; +46[label=4]; +47[label=42]; +48[label=5]; +49[label=30]; +50[label=58]; +51[label=115]; +52[label=16]; +53[label=106]; +54[label=52]; +55[label=End]; +56[label=7]; +57[label=65]; +58[label=10]; +59[label=27]; +60[label=6]; +61[label=Start]; +62[label=45]; +63[label=13]; +64[label=47]; +65[label=32]; +66[label=74]; +67[label=15]; +68[label=118]; +69[label=34]; +70[label=128]; +71[label=117]; +72[label=26]; +73[label=21]; +74[label=105]; +75[label=86]; +76[label=23]; +77[label=24]; +78[label=14]; +79[label=20]; +80[label=2]; +81[label=25]; +82[label=84]; +83[label=60]; +84[label=136]; +85[label=63]; +86[label=12]; +87[label=64]; +88[label=66]; +89[label=120]; +90[label=70]; +91[label=68]; +92[label=71]; +93[label=72]; +94[label=73]; +95[label=59]; +96[label=75]; +97[label=77]; +98[label=78]; +99[label=81]; +100[label=80]; +101[label=82]; +102[label=83]; +103[label=87]; +104[label=88]; +105[label=44]; +106[label=89]; +107[label=91]; +108[label=131]; +109[label=19]; +110[label=116]; +111[label=122]; +112[label=92]; +113[label=102]; +114[label=93]; +115[label=135]; +116[label=124]; +117[label=98]; +118[label=43]; +119[label=100]; +120[label=101]; +121[label=3]; +122[label=104]; +123[label=33]; +124[label=107]; +125[label=109]; +126[label=125]; +127[label=110]; +128[label=97]; +129[label=112]; +130[label=1]; +131[label=113]; +132[label=69]; +133[label=114]; +134[label=119]; +135[label=51]; +136[label=94]; +137[label=121]; +138[label=123]; +0->55 ; +1->55 ; +2->84 ; +2->0 ; +3->84 ; +3->0 ; +4->84 ; +4->0 ; +5->0 ; +6->84 ; +6->0 ; +7->84 ; +7->0 ; +8->93 ; +8->94 ; +8->66 ; +9->91 ; +9->132 ; +9->90 ; +10->88 ; +10->42 ; +10->91 ; +11->87 ; +11->57 ; +11->88 ; +12->19 ; +12->23 ; +12->22 ; +13->133 ; +13->51 ; +13->110 ; +14->42 ; +14->91 ; +14->132 ; +15->92 ; +15->93 ; +15->94 ; +16->24 ; +16->100 ; +16->99 ; +17->137 ; +17->111 ; +17->138 ; +18->4 ; +18->3 ; +18->108 ; +19->94 ; +19->66 ; +19->96 ; +20->100 ; +20->99 ; +20->101 ; +21->14 ; +21->9 ; +21->135 ; +22->96 ; +22->36 ; +22->97 ; +23->66 ; +23->96 ; +23->36 ; +24->128 ; +24->117 ; +24->26 ; +25->64 ; +25->10 ; +25->14 ; +26->71 ; +26->68 ; +26->134 ; +27->95 ; +27->83 ; +27->16 ; +28->11 ; +28->64 ; +28->10 ; +29->22 ; +29->50 ; +29->95 ; +30->77 ; +30->81 ; +30->72 ; +31->35 ; +31->125 ; +31->127 ; +32->40 ; +32->34 ; +32->12 ; +33->79 ; +33->73 ; +33->37 ; +34->8 ; +34->19 ; +34->23 ; +35->7 ; +35->6 ; +35->70 ; +36->136 ; +36->45 ; +36->13 ; +37->29 ; +37->41 ; +37->27 ; +38->17 ; +38->122 ; +38->74 ; +39->109 ; +39->79 ; +39->73 ; +40->15 ; +40->8 ; +40->19 ; +41->50 ; +41->95 ; +41->83 ; +42->38 ; +42->75 ; +42->103 ; +43->23 ; +43->22 ; +43->50 ; +44->123 ; +44->69 ; +44->40 ; +45->131 ; +45->133 ; +45->51 ; +46->30 ; +46->86 ; +46->63 ; +47->83 ; +47->16 ; +47->20 ; +48->78 ; +48->67 ; +48->52 ; +49->10 ; +49->14 ; +49->9 ; +50->36 ; +50->97 ; +50->98 ; +51->5 ; +51->1 ; +51->115 ; +52->65 ; +52->123 ; +52->69 ; +53->116 ; +53->126 ; +53->7 ; +54->90 ; +54->92 ; +54->93 ; +56->44 ; +56->32 ; +56->109 ; +57->102 ; +57->82 ; +57->38 ; +58->37 ; +58->76 ; +58->77 ; +59->105 ; +59->62 ; +59->11 ; +60->67 ; +60->52 ; +60->44 ; +61->130 ; +62->85 ; +62->87 ; +62->57 ; +63->59 ; +63->28 ; +64->57 ; +64->88 ; +64->42 ; +65->9 ; +65->135 ; +65->54 ; +66->112 ; +66->114 ; +66->136 ; +67->49 ; +67->21 ; +67->65 ; +68->84 ; +68->0 ; +69->54 ; +69->15 ; +69->8 ; +70->84 ; +70->0 ; +71->115 ; +71->84 ; +71->0 ; +72->118 ; +72->105 ; +72->62 ; +73->43 ; +73->29 ; +73->41 ; +74->138 ; +74->116 ; +74->126 ; +75->122 ; +75->74 ; +75->53 ; +76->41 ; +76->27 ; +76->47 ; +77->27 ; +77->47 ; +77->118 ; +78->25 ; +78->49 ; +78->21 ; +79->12 ; +79->43 ; +79->29 ; +80->48 ; +80->60 ; +80->56 ; +81->47 ; +81->118 ; +81->105 ; +82->113 ; +82->17 ; +82->122 ; +83->98 ; +83->24 ; +83->100 ; +84->55 ; +85->99 ; +85->101 ; +85->102 ; +86->81 ; +86->72 ; +86->59 ; +87->101 ; +87->102 ; +87->82 ; +88->82 ; +88->38 ; +88->75 ; +89->84 ; +89->0 ; +90->104 ; +90->106 ; +90->31 ; +91->75 ; +91->103 ; +91->104 ; +92->106 ; +92->31 ; +92->107 ; +93->31 ; +93->107 ; +93->112 ; +94->107 ; +94->112 ; +94->114 ; +95->97 ; +95->98 ; +95->24 ; +96->114 ; +96->136 ; +96->45 ; +97->45 ; +97->13 ; +97->128 ; +98->13 ; +98->128 ; +98->117 ; +99->26 ; +99->119 ; +99->120 ; +100->117 ; +100->26 ; +100->119 ; +101->119 ; +101->120 ; +101->113 ; +102->120 ; +102->113 ; +102->17 ; +103->74 ; +103->53 ; +103->124 ; +104->53 ; +104->124 ; +104->35 ; +105->20 ; +105->85 ; +105->87 ; +106->124 ; +106->35 ; +106->125 ; +107->125 ; +107->127 ; +107->18 ; +108->84 ; +108->0 ; +109->34 ; +109->12 ; +109->43 ; +110->1 ; +110->115 ; +110->84 ; +111->84 ; +111->0 ; +112->127 ; +112->18 ; +112->129 ; +113->89 ; +113->137 ; +113->111 ; +114->18 ; +114->129 ; +114->131 ; +115->55 ; +116->84 ; +116->0 ; +117->110 ; +117->71 ; +117->68 ; +118->16 ; +118->20 ; +118->85 ; +119->68 ; +119->134 ; +119->89 ; +120->134 ; +120->89 ; +120->137 ; +121->39 ; +121->33 ; +121->58 ; +122->111 ; +122->138 ; +122->116 ; +123->135 ; +123->54 ; +123->15 ; +124->126 ; +124->7 ; +124->6 ; +125->6 ; +125->70 ; +125->4 ; +126->84 ; +126->0 ; +127->70 ; +127->4 ; +127->3 ; +128->51 ; +128->110 ; +128->71 ; +129->3 ; +129->108 ; +129->2 ; +130->80 ; +130->121 ; +130->46 ; +131->108 ; +131->2 ; +131->5 ; +132->103 ; +132->104 ; +132->106 ; +133->2 ; +133->5 ; +133->1 ; +134->84 ; +134->0 ; +135->132 ; +135->90 ; +135->92 ; +136->129 ; +136->131 ; +136->133 ; +137->84 ; +137->0 ; +138->84 ; +138->0 ; +} diff --git a/tests/out/6.dot b/tests/out/6.dot new file mode 100644 index 0000000..3700b82 --- /dev/null +++ b/tests/out/6.dot @@ -0,0 +1,836 @@ +digraph G { +0[label=241]; +1[label=240]; +2[label=239]; +3[label=237]; +4[label=235]; +5[label=231]; +6[label=230]; +7[label=229]; +8[label=226]; +9[label=224]; +10[label=222]; +11[label=221]; +12[label=216]; +13[label=212]; +14[label=210]; +15[label=209]; +16[label=205]; +17[label=203]; +18[label=201]; +19[label=200]; +20[label=197]; +21[label=192]; +22[label=191]; +23[label=190]; +24[label=234]; +25[label=187]; +26[label=186]; +27[label=183]; +28[label=236]; +29[label=182]; +30[label=178]; +31[label=176]; +32[label=174]; +33[label=173]; +34[label=180]; +35[label=172]; +36[label=170]; +37[label=168]; +38[label=167]; +39[label=166]; +40[label=164]; +41[label=162]; +42[label=161]; +43[label=219]; +44[label=160]; +45[label=158]; +46[label=157]; +47[label=223]; +48[label=155]; +49[label=154]; +50[label=152]; +51[label=151]; +52[label=150]; +53[label=208]; +54[label=149]; +55[label=148]; +56[label=147]; +57[label=145]; +58[label=188]; +59[label=144]; +60[label=143]; +61[label=138]; +62[label=137]; +63[label=134]; +64[label=132]; +65[label=130]; +66[label=213]; +67[label=129]; +68[label=133]; +69[label=127]; +70[label=126]; +71[label=54]; +72[label=211]; +73[label=159]; +74[label=50]; +75[label=48]; +76[label=46]; +77[label=37]; +78[label=238]; +79[label=96]; +80[label=49]; +81[label=218]; +82[label=53]; +83[label=225]; +84[label=61]; +85[label=103]; +86[label=214]; +87[label=163]; +88[label=111]; +89[label=55]; +90[label=62]; +91[label=184]; +92[label=31]; +93[label=194]; +94[label=57]; +95[label=227]; +96[label=56]; +97[label=79]; +98[label=29]; +99[label=139]; +100[label=99]; +101[label=41]; +102[label=28]; +103[label=39]; +104[label=11]; +105[label=90]; +106[label=18]; +107[label=9]; +108[label=36]; +109[label=108]; +110[label=76]; +111[label=22]; +112[label=85]; +113[label=198]; +114[label=8]; +115[label=35]; +116[label=217]; +117[label=40]; +118[label=67]; +119[label=38]; +120[label=17]; +121[label=175]; +122[label=95]; +123[label=30]; +124[label=169]; +125[label=58]; +126[label=115]; +127[label=16]; +128[label=156]; +129[label=106]; +130[label=228]; +131[label=42]; +132[label=5]; +133[label=4]; +134[label=52]; +135[label=140]; +136[label=End]; +137[label=7]; +138[label=65]; +139[label=10]; +140[label=27]; +141[label=6]; +142[label=Start]; +143[label=45]; +144[label=13]; +145[label=47]; +146[label=32]; +147[label=74]; +148[label=15]; +149[label=185]; +150[label=118]; +151[label=34]; +152[label=220]; +153[label=128]; +154[label=117]; +155[label=146]; +156[label=26]; +157[label=21]; +158[label=153]; +159[label=105]; +160[label=86]; +161[label=141]; +162[label=23]; +163[label=24]; +164[label=207]; +165[label=14]; +166[label=20]; +167[label=2]; +168[label=189]; +169[label=179]; +170[label=25]; +171[label=193]; +172[label=84]; +173[label=60]; +174[label=136]; +175[label=63]; +176[label=12]; +177[label=64]; +178[label=204]; +179[label=142]; +180[label=66]; +181[label=181]; +182[label=120]; +183[label=70]; +184[label=68]; +185[label=177]; +186[label=71]; +187[label=72]; +188[label=73]; +189[label=233]; +190[label=215]; +191[label=59]; +192[label=75]; +193[label=165]; +194[label=77]; +195[label=78]; +196[label=199]; +197[label=81]; +198[label=80]; +199[label=82]; +200[label=206]; +201[label=83]; +202[label=87]; +203[label=171]; +204[label=88]; +205[label=44]; +206[label=89]; +207[label=91]; +208[label=131]; +209[label=19]; +210[label=116]; +211[label=232]; +212[label=122]; +213[label=92]; +214[label=102]; +215[label=93]; +216[label=135]; +217[label=124]; +218[label=98]; +219[label=43]; +220[label=100]; +221[label=196]; +222[label=101]; +223[label=3]; +224[label=104]; +225[label=33]; +226[label=107]; +227[label=109]; +228[label=125]; +229[label=195]; +230[label=110]; +231[label=97]; +232[label=112]; +233[label=202]; +234[label=1]; +235[label=113]; +236[label=69]; +237[label=114]; +238[label=119]; +239[label=51]; +240[label=94]; +241[label=121]; +242[label=123]; +0->136 ; +1->136 ; +2->136 ; +3->136 ; +4->136 ; +5->189 ; +5->24 ; +6->211 ; +6->189 ; +7->5 ; +7->211 ; +8->130 ; +8->7 ; +9->8 ; +9->95 ; +10->9 ; +10->83 ; +11->47 ; +11->9 ; +12->81 ; +12->43 ; +13->86 ; +13->190 ; +14->13 ; +14->66 ; +15->72 ; +15->13 ; +16->164 ; +16->53 ; +17->16 ; +17->200 ; +18->17 ; +18->178 ; +19->233 ; +19->17 ; +20->196 ; +20->19 ; +21->93 ; +21->229 ; +22->171 ; +22->93 ; +23->21 ; +23->171 ; +24->136 ; +25->168 ; +25->23 ; +26->58 ; +26->168 ; +27->149 ; +27->26 ; +28->136 ; +29->91 ; +29->149 ; +30->34 ; +30->181 ; +31->30 ; +31->169 ; +32->31 ; +32->185 ; +33->121 ; +33->31 ; +34->29 ; +34->27 ; +35->32 ; +35->121 ; +36->35 ; +36->33 ; +37->36 ; +37->203 ; +38->124 ; +38->36 ; +39->37 ; +39->124 ; +40->39 ; +40->38 ; +41->40 ; +41->193 ; +42->87 ; +42->40 ; +43->11 ; +43->10 ; +44->41 ; +44->87 ; +45->44 ; +45->42 ; +46->73 ; +46->44 ; +47->83 ; +47->8 ; +48->46 ; +48->45 ; +49->128 ; +49->46 ; +50->49 ; +50->48 ; +51->158 ; +51->49 ; +52->50 ; +52->158 ; +53->14 ; +53->72 ; +54->51 ; +54->50 ; +55->52 ; +55->51 ; +56->54 ; +56->52 ; +57->56 ; +57->55 ; +58->23 ; +58->22 ; +59->155 ; +59->56 ; +60->57 ; +60->155 ; +61->99 ; +61->135 ; +62->136 ; +63->136 ; +64->174 ; +64->62 ; +65->174 ; +65->62 ; +66->190 ; +66->12 ; +67->174 ; +67->62 ; +68->62 ; +69->174 ; +69->62 ; +70->174 ; +70->62 ; +71->187 ; +71->188 ; +71->147 ; +72->66 ; +72->86 ; +73->42 ; +73->41 ; +74->184 ; +74->236 ; +74->183 ; +75->180 ; +75->118 ; +75->184 ; +76->177 ; +76->138 ; +76->180 ; +77->89 ; +77->96 ; +77->94 ; +78->136 ; +79->237 ; +79->126 ; +79->210 ; +80->118 ; +80->184 ; +80->236 ; +81->152 ; +81->11 ; +82->186 ; +82->187 ; +82->188 ; +83->95 ; +83->130 ; +84->97 ; +84->198 ; +84->197 ; +85->241 ; +85->212 ; +85->242 ; +86->12 ; +86->116 ; +87->193 ; +87->39 ; +88->67 ; +88->65 ; +88->208 ; +89->188 ; +89->147 ; +89->192 ; +90->198 ; +90->197 ; +90->199 ; +91->26 ; +91->25 ; +92->80 ; +92->74 ; +92->239 ; +93->221 ; +93->20 ; +94->192 ; +94->110 ; +94->194 ; +95->7 ; +95->6 ; +96->147 ; +96->192 ; +96->110 ; +97->231 ; +97->218 ; +97->100 ; +98->145 ; +98->75 ; +98->80 ; +99->161 ; +99->179 ; +100->154 ; +100->150 ; +100->238 ; +101->191 ; +101->173 ; +101->84 ; +102->76 ; +102->145 ; +102->75 ; +103->94 ; +103->125 ; +103->191 ; +104->163 ; +104->170 ; +104->156 ; +105->109 ; +105->227 ; +105->230 ; +106->115 ; +106->108 ; +106->77 ; +107->166 ; +107->157 ; +108->71 ; +108->89 ; +108->96 ; +109->70 ; +109->69 ; +109->153 ; +110->240 ; +110->122 ; +110->79 ; +111->103 ; +111->117 ; +111->101 ; +112->85 ; +112->224 ; +112->159 ; +113->19 ; +113->18 ; +114->106 ; +114->209 ; +114->166 ; +115->82 ; +115->71 ; +115->89 ; +116->43 ; +116->152 ; +117->125 ; +117->191 ; +117->173 ; +118->112 ; +118->160 ; +118->202 ; +119->96 ; +119->94 ; +119->125 ; +120->225 ; +120->151 ; +120->115 ; +121->185 ; +121->30 ; +122->235 ; +122->237 ; +122->126 ; +123->75 ; +123->80 ; +123->74 ; +124->203 ; +124->35 ; +125->110 ; +125->194 ; +125->195 ; +126->68 ; +126->63 ; +126->216 ; +127->146 ; +127->225 ; +127->151 ; +128->45 ; +128->73 ; +129->217 ; +129->228 ; +129->70 ; +130->6 ; +130->5 ; +131->173 ; +131->84 ; +131->90 ; +132->176 ; +132->144 ; +132->165 ; +133->139 ; +133->104 ; +133->176 ; +134->183 ; +134->186 ; +134->187 ; +135->179 ; +135->60 ; +137->127 ; +137->120 ; +137->106 ; +138->201 ; +138->172 ; +138->112 ; +139->111 ; +139->162 ; +140->205 ; +140->143 ; +140->76 ; +141->165 ; +141->148 ; +141->127 ; +142->0 ; +142->1 ; +142->2 ; +142->3 ; +142->61 ; +142->78 ; +142->167 ; +142->223 ; +142->234 ; +143->175 ; +143->177 ; +143->138 ; +144->140 ; +144->102 ; +145->138 ; +145->180 ; +145->118 ; +146->74 ; +146->239 ; +146->134 ; +147->213 ; +147->215 ; +147->240 ; +148->123 ; +148->92 ; +148->146 ; +149->25 ; +149->58 ; +150->174 ; +150->62 ; +151->134 ; +151->82 ; +151->71 ; +152->10 ; +152->47 ; +153->174 ; +153->62 ; +154->216 ; +154->174 ; +154->62 ; +155->55 ; +155->54 ; +156->219 ; +156->205 ; +156->143 ; +157->119 ; +157->103 ; +157->117 ; +158->48 ; +158->128 ; +159->242 ; +159->217 ; +159->228 ; +160->224 ; +160->159 ; +160->129 ; +161->60 ; +161->59 ; +162->117 ; +162->101 ; +162->131 ; +163->101 ; +163->131 ; +163->219 ; +164->15 ; +164->14 ; +165->98 ; +165->123 ; +165->92 ; +166->77 ; +166->119 ; +166->103 ; +167->141 ; +167->137 ; +167->114 ; +168->22 ; +168->21 ; +169->181 ; +169->29 ; +170->131 ; +170->219 ; +170->205 ; +171->229 ; +171->221 ; +172->214 ; +172->85 ; +172->224 ; +173->195 ; +173->97 ; +173->198 ; +174->136 ; +175->197 ; +175->199 ; +175->201 ; +176->170 ; +176->156 ; +176->140 ; +177->199 ; +177->201 ; +177->172 ; +178->200 ; +178->164 ; +179->59 ; +179->57 ; +180->172 ; +180->112 ; +180->160 ; +181->27 ; +181->91 ; +182->174 ; +182->62 ; +183->204 ; +183->206 ; +183->105 ; +184->160 ; +184->202 ; +184->204 ; +185->169 ; +185->34 ; +186->206 ; +186->105 ; +186->207 ; +187->105 ; +187->207 ; +187->213 ; +188->207 ; +188->213 ; +188->215 ; +189->4 ; +189->28 ; +190->116 ; +190->81 ; +191->194 ; +191->195 ; +191->97 ; +192->215 ; +192->240 ; +192->122 ; +193->38 ; +193->37 ; +194->122 ; +194->79 ; +194->231 ; +195->79 ; +195->231 ; +195->218 ; +196->18 ; +196->233 ; +197->100 ; +197->220 ; +197->222 ; +198->218 ; +198->100 ; +198->220 ; +199->220 ; +199->222 ; +199->214 ; +200->53 ; +200->15 ; +201->222 ; +201->214 ; +201->85 ; +202->159 ; +202->129 ; +202->226 ; +203->33 ; +203->32 ; +204->129 ; +204->226 ; +204->109 ; +205->90 ; +205->175 ; +205->177 ; +206->226 ; +206->109 ; +206->227 ; +207->227 ; +207->230 ; +207->88 ; +208->174 ; +208->62 ; +209->108 ; +209->77 ; +209->119 ; +210->63 ; +210->216 ; +210->174 ; +211->24 ; +211->4 ; +212->174 ; +212->62 ; +213->230 ; +213->88 ; +213->232 ; +214->182 ; +214->241 ; +214->212 ; +215->88 ; +215->232 ; +215->235 ; +216->136 ; +217->174 ; +217->62 ; +218->210 ; +218->154 ; +218->150 ; +219->84 ; +219->90 ; +219->175 ; +220->150 ; +220->238 ; +220->182 ; +221->113 ; +221->196 ; +222->238 ; +222->182 ; +222->241 ; +223->114 ; +223->107 ; +224->212 ; +224->242 ; +224->217 ; +225->239 ; +225->134 ; +225->82 ; +226->228 ; +226->70 ; +226->69 ; +227->69 ; +227->153 ; +227->67 ; +228->174 ; +228->62 ; +229->20 ; +229->113 ; +230->153 ; +230->67 ; +230->65 ; +231->126 ; +231->210 ; +231->154 ; +232->65 ; +232->208 ; +232->64 ; +233->178 ; +233->16 ; +234->133 ; +234->132 ; +234->141 ; +235->208 ; +235->64 ; +235->68 ; +236->202 ; +236->204 ; +236->206 ; +237->64 ; +237->68 ; +237->63 ; +238->174 ; +238->62 ; +239->236 ; +239->183 ; +239->186 ; +240->232 ; +240->235 ; +240->237 ; +241->174 ; +241->62 ; +242->174 ; +242->62 ; +} From a898619e9076f8914fe242aa889056d4f5352c3b Mon Sep 17 00:00:00 2001 From: Victor Baldin Date: Tue, 9 Dec 2025 16:35:33 +0000 Subject: [PATCH 5/6] add 7, 8 tests --- include/graphs/graph.hh | 59 +++++++++++++++++++++++++++ tests/in/7.in | 3 ++ tests/in/8.in | 30 ++++++++++++++ tests/out/7.dot | 13 ++++++ tests/out/8.dot | 88 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 tests/in/7.in create mode 100644 tests/in/8.in create mode 100644 tests/out/7.dot create mode 100644 tests/out/8.dot diff --git a/include/graphs/graph.hh b/include/graphs/graph.hh index 99086cd..113c941 100644 --- a/include/graphs/graph.hh +++ b/include/graphs/graph.hh @@ -11,6 +11,12 @@ namespace graph { template class Graph final { + enum class VertexColor { + kWhite, + kGrey, + kBlack, + }; + public: Graph(const T& start = T(), const T& end = T()) : start_(start), @@ -45,6 +51,25 @@ class Graph final { return true; } + std::vector topologicalSort() const { + std::vector result; + + std::unordered_map colors; + for (const auto& [v, _] : adj_list_) { + colors.emplace(v, VertexColor::kWhite); + } + auto post_order_func = [&result](T node) { result.push_back(node); }; + + for (auto& [v, color] : colors) { + if (color == VertexColor::kWhite) { + dfs(adj_list_, colors, v, post_order_func); + } + } + + std::reverse(std::begin(result), std::end(result)); + return result; + } + void dump() const { using namespace boost; @@ -86,5 +111,39 @@ class Graph final { } } } + + static void dfs(const std::unordered_map>& graph, + std::unordered_map& color, T node, + const std::function& post_order_func) { + std::stack nodes; + nodes.push(node); + + while (!nodes.empty()) { + auto from = nodes.top(); + + if (color[from] == VertexColor::kGrey) { + color[from] = VertexColor::kBlack; + post_order_func(from); + nodes.pop(); + continue; + } else if (color[from] == VertexColor::kBlack) { + nodes.pop(); + continue; + } + + color[from] = VertexColor::kGrey; + auto adj = graph.at(from); + + for (const auto& a : adj) { + const auto& to = a; + if (color[to] == VertexColor::kWhite) { + nodes.push(to); + } else if (color[to] == VertexColor::kGrey) { + throw std::runtime_error( + "Graph has cycle. Topological sort impossible."); + } + } + } + } }; } // namespace graph diff --git a/tests/in/7.in b/tests/in/7.in new file mode 100644 index 0000000..2b3ea1f --- /dev/null +++ b/tests/in/7.in @@ -0,0 +1,3 @@ +1 2 +2 3 +3 4 diff --git a/tests/in/8.in b/tests/in/8.in new file mode 100644 index 0000000..7d783d0 --- /dev/null +++ b/tests/in/8.in @@ -0,0 +1,30 @@ +1 5 6 +2 6 7 +3 7 8 +4 8 9 +5 10 +6 10 11 +7 11 12 +8 12 13 +9 13 14 +10 15 +11 15 16 +12 16 17 +13 17 18 +14 18 19 +15 20 +16 20 21 +17 21 22 +18 22 23 +19 23 24 +20 25 +21 25 26 +22 26 27 +23 27 28 +24 28 29 +25 30 +26 30 +27 30 +28 30 +29 30 +30 diff --git a/tests/out/7.dot b/tests/out/7.dot new file mode 100644 index 0000000..7e289d0 --- /dev/null +++ b/tests/out/7.dot @@ -0,0 +1,13 @@ +digraph G { +0[label=4]; +1[label=3]; +2[label=1]; +3[label=2]; +4[label=End]; +5[label=Start]; +0->4 ; +1->0 ; +2->3 ; +3->1 ; +5->2 ; +} diff --git a/tests/out/8.dot b/tests/out/8.dot new file mode 100644 index 0000000..3eca985 --- /dev/null +++ b/tests/out/8.dot @@ -0,0 +1,88 @@ +digraph G { +0[label=29]; +1[label=28]; +2[label=11]; +3[label=18]; +4[label=4]; +5[label=9]; +6[label=1]; +7[label=22]; +8[label=8]; +9[label=17]; +10[label=19]; +11[label=30]; +12[label=6]; +13[label=3]; +14[label=16]; +15[label=5]; +16[label=End]; +17[label=7]; +18[label=10]; +19[label=27]; +20[label=Start]; +21[label=13]; +22[label=15]; +23[label=12]; +24[label=14]; +25[label=26]; +26[label=20]; +27[label=21]; +28[label=23]; +29[label=24]; +30[label=2]; +31[label=25]; +0->11 ; +1->11 ; +2->22 ; +2->14 ; +3->7 ; +3->28 ; +4->8 ; +4->5 ; +5->21 ; +5->24 ; +6->15 ; +6->12 ; +7->25 ; +7->19 ; +8->23 ; +8->21 ; +9->27 ; +9->7 ; +10->28 ; +10->29 ; +11->16 ; +12->18 ; +12->2 ; +13->17 ; +13->8 ; +14->26 ; +14->27 ; +15->18 ; +17->2 ; +17->23 ; +18->22 ; +19->11 ; +20->4 ; +20->6 ; +20->13 ; +20->30 ; +21->9 ; +21->3 ; +22->26 ; +23->14 ; +23->9 ; +24->3 ; +24->10 ; +25->11 ; +26->31 ; +27->31 ; +27->25 ; +28->19 ; +28->1 ; +29->1 ; +29->0 ; +30->12 ; +30->17 ; +31->11 ; +} From eea72eead85032722b463202835dedb7b21b5e66 Mon Sep 17 00:00:00 2001 From: Victor Baldin Date: Tue, 9 Dec 2025 21:30:39 +0000 Subject: [PATCH 6/6] add topo sort --- CMakeLists.txt | 2 + conan.lock | 2 + conanfile.txt | 1 + include/graphs/graph.hh | 189 ++--- src/main.cc | 24 +- tests/CMakeLists.txt | 5 + tests/out/1.dot | 26 +- tests/out/2.dot | 128 ++-- tests/out/3.dot | 72 +- tests/out/4.dot | 98 +-- tests/out/5.dot | 990 ++++++++++++------------- tests/out/6.dot | 1564 +++++++++++++++++++-------------------- tests/out/7.dot | 20 +- tests/out/8.dot | 164 ++-- tests/unit_tests.cc | 119 +++ 15 files changed, 1759 insertions(+), 1645 deletions(-) create mode 100644 tests/unit_tests.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 6519c40..2061569 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.14) project(graphs) find_package(Boost REQUIRED) +find_package(GTest REQUIRED) include(CTest) +include(GoogleTest) add_library(graphs INTERFACE) target_include_directories(graphs INTERFACE include) diff --git a/conan.lock b/conan.lock index 16d03a2..73ebb1a 100644 --- a/conan.lock +++ b/conan.lock @@ -3,10 +3,12 @@ "requires": [ "zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1733936244.862", "libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1722218217.276", + "gtest/1.17.0#5224b3b3ff3b4ce1133cbdd27d53ee7d%1755784855.585", "bzip2/1.0.8#d00dac990f08d991998d624be81a9526%1724661266.998", "boost/1.86.0#0675eb54da69d8eed264eb22203a7117%1761059017.02" ], "build_requires": [ + "cmake/4.2.0#ae0a44f44a1ef9ab68fd4b3e9a1f8671%1764093466.37", "b2/5.2.1#91bc73931a0acb655947a81569ed8b80%1718416612.241" ], "python_requires": [], diff --git a/conanfile.txt b/conanfile.txt index 4693463..3a8224f 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,6 @@ [requires] boost/1.86.0 +gtest/1.17.0 [generators] CMakeDeps diff --git a/include/graphs/graph.hh b/include/graphs/graph.hh index 113c941..3f430c3 100644 --- a/include/graphs/graph.hh +++ b/include/graphs/graph.hh @@ -2,8 +2,7 @@ #include #include -#include -#include +#include #include #include @@ -11,139 +10,145 @@ namespace graph { template class Graph final { - enum class VertexColor { - kWhite, - kGrey, - kBlack, - }; - public: - Graph(const T& start = T(), const T& end = T()) - : start_(start), - end_(end), - adj_list_{{start, std::vector{}}, {end_, std::vector{}}} {} + using AdjMap = std::unordered_map>; - bool insert(const T& v, const std::vector& adj) { - for (const auto& a : adj) { - auto it = adj_list_.find(a); - if (it == adj_list_.end()) { - adj_list_.emplace( - a, std::vector{end_}); // speculatively mark as end node - } - ++in_deg_[a]; + Graph() noexcept = default; + + Graph( + std::initializer_list>> adj_list) { + for (const auto& [v, a] : adj_list) { + insert(v, std::vector(a)); } + } - if (in_deg_.find(v) == in_deg_.end()) { - in_deg_.emplace(v, 0); + bool insert(const T& v, const std::vector& adj) { + auto it = adj_list_.find(v); + if (it != adj_list_.end()) { + return false; } - auto [it, ins] = - adj_list_.emplace(v, adj.empty() ? std::vector{end_} : adj); - if (!ins) { - if (it->second == std::vector{end_} && !adj.empty()) { - it->second = adj; - } else { - return false; - } + for (const auto& a : adj) { + auto it = adj_list_.find(a); + ++in_deg_[a]; + out_deg_.emplace(a, 0); } - linkToStart(); + in_deg_.emplace(v, 0); + out_deg_[v] = adj.size(); + adj_list_.emplace(v, adj); return true; } std::vector topologicalSort() const { - std::vector result; + std::vector order; + std::queue q; - std::unordered_map colors; - for (const auto& [v, _] : adj_list_) { - colors.emplace(v, VertexColor::kWhite); + for (auto& [u, cnt] : in_deg_) { + if (cnt == 0) { + q.push(u); + } } - auto post_order_func = [&result](T node) { result.push_back(node); }; - for (auto& [v, color] : colors) { - if (color == VertexColor::kWhite) { - dfs(adj_list_, colors, v, post_order_func); + order.reserve(in_deg_.size()); + auto id = in_deg_; + + while (!q.empty()) { + T u = q.front(); + q.pop(); + + order.push_back(u); + + auto it = adj_list_.find(u); + + if (it != adj_list_.end()) { + for (auto& v : it->second) { + if (--id[v] == 0) { + q.push(v); + } + } } } - std::reverse(std::begin(result), std::end(result)); - return result; + if (order.size() != in_deg_.size()) { + throw std::runtime_error("Graph has cycle"); + } + return order; } - void dump() const { + void dump(std::ostream& os) const { using namespace boost; using OutGraph = adjacency_list, property>; + OutGraph g; + auto start = add_vertex(g); + auto end = add_vertex(g); + put(vertex_name, g, start, "Start"); + put(vertex_name, g, end, "End"); + std::unordered_map vd; - vd.reserve(adj_list_.size()); - for (const auto& [v, _] : adj_list_) { + vd.reserve(in_deg_.size()); + for (const auto& [v, _] : in_deg_) { auto d = add_vertex(g); - put(vertex_name, g, d, v); + put(vertex_name, g, d, std::to_string(v)); vd.emplace(v, d); } - for (auto& [v, adj] : adj_list_) { + for (const auto& [v, cnt] : in_deg_) { + if (cnt == 0) { + add_edge(start, vd[v], g); + } + } + + for (const auto& [v, cnt] : out_deg_) { + if (cnt == 0) { + add_edge(vd[v], end, g); + } + } + + for (const auto& [v, adj] : adj_list_) { for (const auto& a : adj) { add_edge(vd[v], vd[a], g); } } - write_graphviz(std::cout, g, make_label_writer(get(vertex_name, g))); + write_graphviz(os, g, make_label_writer(get(vertex_name, g))); } private: - T start_; - T end_; - std::unordered_map> adj_list_; - std::unordered_map in_deg_; - - void linkToStart() { - auto& start_nodes = adj_list_[start_]; - start_nodes.clear(); - - for (const auto& [v, c] : in_deg_) { - if (c == 0) { - start_nodes.push_back(v); - } - } - } + AdjMap adj_list_; - static void dfs(const std::unordered_map>& graph, - std::unordered_map& color, T node, - const std::function& post_order_func) { - std::stack nodes; - nodes.push(node); - - while (!nodes.empty()) { - auto from = nodes.top(); - - if (color[from] == VertexColor::kGrey) { - color[from] = VertexColor::kBlack; - post_order_func(from); - nodes.pop(); - continue; - } else if (color[from] == VertexColor::kBlack) { - nodes.pop(); - continue; - } + using DegreeMap = std::unordered_map; + DegreeMap in_deg_; + DegreeMap out_deg_; +}; - color[from] = VertexColor::kGrey; - auto adj = graph.at(from); +template +inline Graph readGraph(std::istream& is) { + graph::Graph g; - for (const auto& a : adj) { - const auto& to = a; - if (color[to] == VertexColor::kWhite) { - nodes.push(to); - } else if (color[to] == VertexColor::kGrey) { - throw std::runtime_error( - "Graph has cycle. Topological sort impossible."); - } - } + std::string line; + while (std::getline(is, line)) { + if (line.empty()) { + break; } + + std::istringstream ss(line); + T u; + ss >> u; + + std::vector adj; + T v; + while (ss >> v) { + adj.push_back(v); + } + g.insert(u, adj); } -}; + + return g; +} } // namespace graph diff --git a/src/main.cc b/src/main.cc index e3589cf..a6d0a52 100644 --- a/src/main.cc +++ b/src/main.cc @@ -35,28 +35,8 @@ int main(int argc, char** argv) try { return 0; } - graph::Graph g("Start", "End"); - - std::string line; - while (std::getline(std::cin, line)) { - if (line.empty()) { - break; - } - - std::istringstream ss(line); - std::string u; - ss >> u; - - std::vector adj; - std::string v; - while (ss >> v) { - adj.push_back(v); - } - - g.insert(u, adj); - } - - g.dump(); + auto g = graph::readGraph(std::cin); + g.dump(std::cout); return 0; } catch (std::exception& e) { std::cerr << e.what() << std::endl; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dc09882..f7b9078 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,2 +1,7 @@ add_test(NAME GraphvizOutputTest COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/run_tests.py --executable $) + +add_executable(unit_test unit_tests.cc) +target_link_libraries(unit_test gtest::gtest graphs) + +gtest_discover_tests(unit_test) diff --git a/tests/out/1.dot b/tests/out/1.dot index 0cf8e08..de9caed 100644 --- a/tests/out/1.dot +++ b/tests/out/1.dot @@ -1,17 +1,17 @@ digraph G { -0[label=9]; -1[label=2]; -2[label=7]; +0[label=Start]; +1[label=End]; +2[label=9]; 3[label=3]; -4[label=5]; -5[label=End]; -6[label=Start]; -0->5 ; -1->5 ; -2->0 ; +4[label=2]; +5[label=7]; +6[label=5]; +0->3 ; +2->1 ; +3->6 ; +3->5 ; 3->4 ; -3->2 ; -3->1 ; -4->0 ; -6->3 ; +4->1 ; +5->2 ; +6->2 ; } diff --git a/tests/out/2.dot b/tests/out/2.dot index 7c5dc78..0c15d86 100644 --- a/tests/out/2.dot +++ b/tests/out/2.dot @@ -1,71 +1,71 @@ digraph G { -0[label=25]; -1[label=24]; -2[label=23]; -3[label=21]; -4[label=20]; -5[label=14]; -6[label=12]; -7[label=15]; -8[label=13]; -9[label=Start]; -10[label=10]; -11[label=End]; -12[label=2]; -13[label=19]; -14[label=6]; -15[label=16]; -16[label=3]; -17[label=5]; -18[label=17]; -19[label=7]; -20[label=4]; -21[label=8]; -22[label=22]; -23[label=1]; -24[label=9]; -25[label=18]; -26[label=11]; -0->11 ; -1->0 ; +0[label=Start]; +1[label=End]; +2[label=25]; +3[label=24]; +4[label=23]; +5[label=22]; +6[label=21]; +7[label=20]; +8[label=19]; +9[label=18]; +10[label=17]; +11[label=16]; +12[label=15]; +13[label=14]; +14[label=2]; +15[label=6]; +16[label=1]; +17[label=3]; +18[label=7]; +19[label=4]; +20[label=8]; +21[label=5]; +22[label=9]; +23[label=10]; +24[label=11]; +25[label=12]; +26[label=13]; +0->16 ; 2->1 ; -3->22 ; -4->0 ; -5->7 ; -5->13 ; -6->8 ; -6->18 ; -7->4 ; -8->5 ; -8->25 ; -9->23 ; -10->7 ; -12->16 ; -12->19 ; -13->4 ; -13->1 ; -14->19 ; -14->26 ; +3->2 ; +4->3 ; +5->4 ; +6->5 ; +7->2 ; +8->7 ; +8->3 ; +9->8 ; +9->4 ; +10->9 ; +10->5 ; +11->10 ; +11->6 ; +12->7 ; +13->12 ; +13->8 ; +14->17 ; +14->18 ; 15->18 ; -15->3 ; -16->20 ; -16->21 ; -17->10 ; +15->24 ; +16->14 ; +16->15 ; +17->19 ; +17->20 ; +18->20 ; 18->25 ; -18->22 ; 19->21 ; -19->6 ; -20->17 ; -20->24 ; -21->24 ; -21->8 ; -22->2 ; +19->22 ; +20->22 ; +20->26 ; +21->23 ; +22->23 ; +22->13 ; 23->12 ; -23->14 ; -24->10 ; -24->5 ; -25->13 ; -25->2 ; -26->6 ; -26->15 ; +24->25 ; +24->11 ; +25->26 ; +25->10 ; +26->13 ; +26->9 ; } diff --git a/tests/out/3.dot b/tests/out/3.dot index 0bc0e0a..c3e7df7 100644 --- a/tests/out/3.dot +++ b/tests/out/3.dot @@ -1,42 +1,42 @@ digraph G { -0[label=14]; -1[label=12]; +0[label=Start]; +1[label=End]; 2[label=15]; -3[label=13]; -4[label=Start]; -5[label=10]; -6[label=End]; -7[label=2]; -8[label=3]; -9[label=5]; -10[label=4]; -11[label=6]; -12[label=7]; -13[label=8]; -14[label=1]; -15[label=9]; -16[label=11]; +3[label=14]; +4[label=2]; +5[label=3]; +6[label=1]; +7[label=4]; +8[label=5]; +9[label=6]; +10[label=7]; +11[label=8]; +12[label=9]; +13[label=10]; +14[label=11]; +15[label=12]; +16[label=13]; 0->6 ; -1->6 ; -2->6 ; -3->6 ; -4->14 ; -5->6 ; -7->10 ; -7->9 ; -8->11 ; -8->12 ; -9->5 ; +2->1 ; +3->1 ; +4->7 ; +4->8 ; +5->9 ; +5->10 ; +6->4 ; +6->5 ; +7->11 ; +7->12 ; +8->13 ; +8->14 ; +9->15 ; 9->16 ; -10->13 ; -10->15 ; +10->3 ; +10->2 ; 11->1 ; -11->3 ; -12->0 ; -12->2 ; -13->6 ; -14->7 ; -14->8 ; -15->6 ; -16->6 ; +12->1 ; +13->1 ; +14->1 ; +15->1 ; +16->1 ; } diff --git a/tests/out/4.dot b/tests/out/4.dot index 0fed8e7..b8bab33 100644 --- a/tests/out/4.dot +++ b/tests/out/4.dot @@ -1,54 +1,54 @@ digraph G { -0[label=20]; -1[label=10]; -2[label=8]; -3[label=17]; -4[label=7]; -5[label=End]; -6[label=2]; -7[label=18]; -8[label=11]; -9[label=9]; -10[label=1]; -11[label=16]; -12[label=3]; -13[label=5]; -14[label=12]; -15[label=4]; -16[label=Start]; -17[label=15]; +0[label=Start]; +1[label=End]; +2[label=20]; +3[label=19]; +4[label=10]; +5[label=18]; +6[label=9]; +7[label=17]; +8[label=8]; +9[label=2]; +10[label=15]; +11[label=11]; +12[label=1]; +13[label=14]; +14[label=3]; +15[label=16]; +16[label=12]; +17[label=4]; 18[label=13]; -19[label=14]; -20[label=19]; -21[label=6]; -0->5 ; -1->0 ; -2->9 ; -2->7 ; -3->7 ; +19[label=5]; +20[label=6]; +21[label=7]; +0->12 ; +2->1 ; +3->2 ; 4->2 ; -4->3 ; -6->12 ; -6->14 ; -7->20 ; -8->14 ; -9->1 ; -9->20 ; -10->6 ; -10->8 ; -11->3 ; -12->15 ; -12->18 ; -13->21 ; -13->17 ; +5->3 ; +6->4 ; +6->3 ; +7->5 ; +8->6 ; +8->5 ; +9->14 ; +9->16 ; +10->15 ; +11->16 ; +12->9 ; +12->11 ; +13->10 ; +14->17 ; 14->18 ; -15->13 ; -15->19 ; -16->10 ; -17->11 ; -18->19 ; -19->17 ; -20->0 ; -21->4 ; -21->11 ; +15->7 ; +16->18 ; +17->19 ; +17->13 ; +18->13 ; +19->20 ; +19->10 ; +20->21 ; +20->15 ; +21->8 ; +21->7 ; } diff --git a/tests/out/5.dot b/tests/out/5.dot index bba26fc..1850c7d 100644 --- a/tests/out/5.dot +++ b/tests/out/5.dot @@ -1,527 +1,527 @@ digraph G { -0[label=137]; -1[label=134]; -2[label=132]; -3[label=130]; -4[label=129]; -5[label=133]; -6[label=127]; -7[label=126]; -8[label=54]; -9[label=50]; -10[label=48]; -11[label=46]; -12[label=37]; -13[label=96]; -14[label=49]; -15[label=53]; -16[label=61]; -17[label=103]; -18[label=111]; -19[label=55]; -20[label=62]; -21[label=31]; -22[label=57]; -23[label=56]; -24[label=79]; -25[label=29]; -26[label=99]; -27[label=41]; -28[label=28]; -29[label=39]; -30[label=11]; -31[label=90]; -32[label=18]; -33[label=9]; -34[label=36]; -35[label=108]; -36[label=76]; -37[label=22]; -38[label=85]; -39[label=8]; -40[label=35]; -41[label=40]; -42[label=67]; -43[label=38]; -44[label=17]; -45[label=95]; -46[label=4]; -47[label=42]; -48[label=5]; -49[label=30]; -50[label=58]; -51[label=115]; -52[label=16]; -53[label=106]; -54[label=52]; -55[label=End]; -56[label=7]; -57[label=65]; -58[label=10]; -59[label=27]; -60[label=6]; -61[label=Start]; -62[label=45]; -63[label=13]; -64[label=47]; -65[label=32]; -66[label=74]; -67[label=15]; -68[label=118]; -69[label=34]; -70[label=128]; -71[label=117]; -72[label=26]; -73[label=21]; -74[label=105]; -75[label=86]; -76[label=23]; -77[label=24]; -78[label=14]; -79[label=20]; -80[label=2]; -81[label=25]; -82[label=84]; -83[label=60]; -84[label=136]; -85[label=63]; -86[label=12]; -87[label=64]; -88[label=66]; -89[label=120]; -90[label=70]; -91[label=68]; -92[label=71]; -93[label=72]; -94[label=73]; -95[label=59]; -96[label=75]; -97[label=77]; -98[label=78]; -99[label=81]; -100[label=80]; -101[label=82]; -102[label=83]; -103[label=87]; -104[label=88]; -105[label=44]; -106[label=89]; -107[label=91]; -108[label=131]; -109[label=19]; -110[label=116]; -111[label=122]; -112[label=92]; +0[label=Start]; +1[label=End]; +2[label=137]; +3[label=136]; +4[label=135]; +5[label=134]; +6[label=133]; +7[label=132]; +8[label=131]; +9[label=130]; +10[label=129]; +11[label=128]; +12[label=59]; +13[label=58]; +14[label=57]; +15[label=56]; +16[label=55]; +17[label=54]; +18[label=53]; +19[label=52]; +20[label=51]; +21[label=50]; +22[label=49]; +23[label=48]; +24[label=47]; +25[label=46]; +26[label=45]; +27[label=44]; +28[label=43]; +29[label=42]; +30[label=41]; +31[label=40]; +32[label=39]; +33[label=38]; +34[label=37]; +35[label=36]; +36[label=35]; +37[label=34]; +38[label=33]; +39[label=32]; +40[label=31]; +41[label=30]; +42[label=13]; +43[label=12]; +44[label=11]; +45[label=10]; +46[label=9]; +47[label=8]; +48[label=7]; +49[label=6]; +50[label=5]; +51[label=1]; +52[label=4]; +53[label=3]; +54[label=2]; +55[label=14]; +56[label=15]; +57[label=16]; +58[label=17]; +59[label=18]; +60[label=19]; +61[label=20]; +62[label=21]; +63[label=22]; +64[label=23]; +65[label=24]; +66[label=25]; +67[label=26]; +68[label=27]; +69[label=28]; +70[label=29]; +71[label=60]; +72[label=61]; +73[label=62]; +74[label=63]; +75[label=64]; +76[label=65]; +77[label=66]; +78[label=67]; +79[label=68]; +80[label=69]; +81[label=70]; +82[label=71]; +83[label=72]; +84[label=73]; +85[label=74]; +86[label=75]; +87[label=76]; +88[label=77]; +89[label=78]; +90[label=79]; +91[label=80]; +92[label=81]; +93[label=82]; +94[label=83]; +95[label=84]; +96[label=85]; +97[label=86]; +98[label=87]; +99[label=88]; +100[label=89]; +101[label=90]; +102[label=91]; +103[label=92]; +104[label=93]; +105[label=94]; +106[label=95]; +107[label=96]; +108[label=97]; +109[label=98]; +110[label=99]; +111[label=100]; +112[label=101]; 113[label=102]; -114[label=93]; -115[label=135]; -116[label=124]; -117[label=98]; -118[label=43]; -119[label=100]; -120[label=101]; -121[label=3]; -122[label=104]; -123[label=33]; -124[label=107]; -125[label=109]; -126[label=125]; -127[label=110]; -128[label=97]; -129[label=112]; -130[label=1]; -131[label=113]; -132[label=69]; -133[label=114]; -134[label=119]; -135[label=51]; -136[label=94]; -137[label=121]; -138[label=123]; -0->55 ; -1->55 ; -2->84 ; -2->0 ; -3->84 ; -3->0 ; -4->84 ; -4->0 ; -5->0 ; -6->84 ; -6->0 ; -7->84 ; -7->0 ; -8->93 ; -8->94 ; -8->66 ; -9->91 ; -9->132 ; -9->90 ; -10->88 ; -10->42 ; -10->91 ; -11->87 ; -11->57 ; -11->88 ; -12->19 ; -12->23 ; -12->22 ; -13->133 ; -13->51 ; -13->110 ; -14->42 ; -14->91 ; -14->132 ; -15->92 ; -15->93 ; -15->94 ; -16->24 ; -16->100 ; -16->99 ; -17->137 ; -17->111 ; -17->138 ; -18->4 ; -18->3 ; -18->108 ; -19->94 ; -19->66 ; -19->96 ; -20->100 ; -20->99 ; -20->101 ; -21->14 ; -21->9 ; -21->135 ; -22->96 ; -22->36 ; -22->97 ; -23->66 ; -23->96 ; -23->36 ; -24->128 ; -24->117 ; -24->26 ; -25->64 ; -25->10 ; -25->14 ; -26->71 ; -26->68 ; -26->134 ; -27->95 ; -27->83 ; -27->16 ; -28->11 ; -28->64 ; -28->10 ; -29->22 ; -29->50 ; -29->95 ; -30->77 ; -30->81 ; +114[label=103]; +115[label=104]; +116[label=105]; +117[label=106]; +118[label=107]; +119[label=108]; +120[label=109]; +121[label=110]; +122[label=111]; +123[label=112]; +124[label=113]; +125[label=114]; +126[label=115]; +127[label=116]; +128[label=117]; +129[label=118]; +130[label=119]; +131[label=120]; +132[label=121]; +133[label=122]; +134[label=123]; +135[label=124]; +136[label=125]; +137[label=126]; +138[label=127]; +0->51 ; +2->1 ; +3->1 ; +4->1 ; +5->1 ; +6->2 ; +7->3 ; +7->2 ; +8->3 ; +8->2 ; +9->3 ; +9->2 ; +10->3 ; +10->2 ; +11->3 ; +11->2 ; +12->88 ; +12->89 ; +12->90 ; +13->87 ; +13->88 ; +13->89 ; +14->86 ; +14->87 ; +14->88 ; +15->85 ; +15->86 ; +15->87 ; +16->84 ; +16->85 ; +16->86 ; +17->83 ; +17->84 ; +17->85 ; +18->82 ; +18->83 ; +18->84 ; +19->81 ; +19->82 ; +19->83 ; +20->80 ; +20->81 ; +20->82 ; +21->79 ; +21->80 ; +21->81 ; +22->78 ; +22->79 ; +22->80 ; +23->77 ; +23->78 ; +23->79 ; +24->76 ; +24->77 ; +24->78 ; +25->75 ; +25->76 ; +25->77 ; +26->74 ; +26->75 ; +26->76 ; +27->73 ; +27->74 ; +27->75 ; +28->72 ; +28->73 ; +28->74 ; +29->71 ; +29->72 ; +29->73 ; +30->12 ; +30->71 ; 30->72 ; -31->35 ; -31->125 ; -31->127 ; -32->40 ; -32->34 ; +31->13 ; +31->12 ; +31->71 ; +32->14 ; +32->13 ; 32->12 ; -33->79 ; -33->73 ; -33->37 ; -34->8 ; -34->19 ; -34->23 ; -35->7 ; -35->6 ; -35->70 ; -36->136 ; -36->45 ; -36->13 ; -37->29 ; -37->41 ; -37->27 ; -38->17 ; -38->122 ; -38->74 ; -39->109 ; -39->79 ; -39->73 ; -40->15 ; -40->8 ; -40->19 ; -41->50 ; -41->95 ; -41->83 ; -42->38 ; -42->75 ; -42->103 ; -43->23 ; -43->22 ; -43->50 ; -44->123 ; -44->69 ; -44->40 ; -45->131 ; -45->133 ; -45->51 ; -46->30 ; -46->86 ; +33->15 ; +33->14 ; +33->13 ; +34->16 ; +34->15 ; +34->14 ; +35->17 ; +35->16 ; +35->15 ; +36->18 ; +36->17 ; +36->16 ; +37->19 ; +37->18 ; +37->17 ; +38->20 ; +38->19 ; +38->18 ; +39->21 ; +39->20 ; +39->19 ; +40->22 ; +40->21 ; +40->20 ; +41->23 ; +41->22 ; +41->21 ; +42->68 ; +42->69 ; +43->66 ; +43->67 ; +43->68 ; +44->65 ; +44->66 ; +44->67 ; +45->63 ; +45->64 ; +45->65 ; +46->61 ; +46->62 ; 46->63 ; -47->83 ; -47->16 ; -47->20 ; -48->78 ; -48->67 ; -48->52 ; -49->10 ; -49->14 ; -49->9 ; -50->36 ; -50->97 ; -50->98 ; -51->5 ; -51->1 ; -51->115 ; -52->65 ; -52->123 ; -52->69 ; -53->116 ; -53->126 ; -53->7 ; -54->90 ; -54->92 ; -54->93 ; -56->44 ; -56->32 ; -56->109 ; -57->102 ; -57->82 ; +47->60 ; +47->61 ; +47->62 ; +48->58 ; +48->59 ; +48->60 ; +49->56 ; +49->57 ; +49->58 ; +50->55 ; +50->56 ; +50->57 ; +51->54 ; +51->53 ; +51->52 ; +52->44 ; +52->43 ; +52->42 ; +53->47 ; +53->46 ; +53->45 ; +54->50 ; +54->49 ; +54->48 ; +55->70 ; +55->41 ; +55->40 ; +56->41 ; +56->40 ; +56->39 ; +57->39 ; 57->38 ; +57->37 ; +58->38 ; 58->37 ; -58->76 ; -58->77 ; -59->105 ; -59->62 ; -59->11 ; -60->67 ; -60->52 ; -60->44 ; -61->130 ; -62->85 ; -62->87 ; -62->57 ; -63->59 ; -63->28 ; -64->57 ; -64->88 ; -64->42 ; -65->9 ; -65->135 ; -65->54 ; -66->112 ; -66->114 ; -66->136 ; -67->49 ; -67->21 ; -67->65 ; -68->84 ; -68->0 ; -69->54 ; -69->15 ; -69->8 ; -70->84 ; -70->0 ; -71->115 ; -71->84 ; -71->0 ; -72->118 ; -72->105 ; -72->62 ; -73->43 ; -73->29 ; -73->41 ; -74->138 ; -74->116 ; -74->126 ; -75->122 ; -75->74 ; -75->53 ; -76->41 ; -76->27 ; -76->47 ; -77->27 ; -77->47 ; -77->118 ; -78->25 ; -78->49 ; -78->21 ; -79->12 ; -79->43 ; -79->29 ; -80->48 ; -80->60 ; -80->56 ; -81->47 ; -81->118 ; -81->105 ; -82->113 ; -82->17 ; -82->122 ; -83->98 ; -83->24 ; -83->100 ; -84->55 ; -85->99 ; -85->101 ; -85->102 ; -86->81 ; -86->72 ; -86->59 ; -87->101 ; -87->102 ; -87->82 ; -88->82 ; -88->38 ; -88->75 ; -89->84 ; -89->0 ; -90->104 ; -90->106 ; -90->31 ; -91->75 ; -91->103 ; -91->104 ; -92->106 ; -92->31 ; -92->107 ; -93->31 ; -93->107 ; +58->36 ; +59->36 ; +59->35 ; +59->34 ; +60->35 ; +60->34 ; +60->33 ; +61->34 ; +61->33 ; +61->32 ; +62->33 ; +62->32 ; +62->31 ; +63->32 ; +63->31 ; +63->30 ; +64->31 ; +64->30 ; +64->29 ; +65->30 ; +65->29 ; +65->28 ; +66->29 ; +66->28 ; +66->27 ; +67->28 ; +67->27 ; +67->26 ; +68->27 ; +68->26 ; +68->25 ; +69->25 ; +69->24 ; +69->23 ; +70->24 ; +70->23 ; +70->22 ; +71->89 ; +71->90 ; +71->91 ; +72->90 ; +72->91 ; +72->92 ; +73->91 ; +73->92 ; +73->93 ; +74->92 ; +74->93 ; +74->94 ; +75->93 ; +75->94 ; +75->95 ; +76->94 ; +76->95 ; +76->96 ; +77->95 ; +77->96 ; +77->97 ; +78->96 ; +78->97 ; +78->98 ; +79->97 ; +79->98 ; +79->99 ; +80->98 ; +80->99 ; +80->100 ; +81->99 ; +81->100 ; +81->101 ; +82->100 ; +82->101 ; +82->102 ; +83->101 ; +83->102 ; +83->103 ; +84->102 ; +84->103 ; +84->104 ; +85->103 ; +85->104 ; +85->105 ; +86->104 ; +86->105 ; +86->106 ; +87->105 ; +87->106 ; +87->107 ; +88->106 ; +88->107 ; +88->108 ; +89->107 ; +89->108 ; +89->109 ; +90->108 ; +90->109 ; +90->110 ; +91->109 ; +91->110 ; +91->111 ; +92->110 ; +92->111 ; +92->112 ; +93->111 ; 93->112 ; -94->107 ; +93->113 ; 94->112 ; +94->113 ; 94->114 ; -95->97 ; -95->98 ; -95->24 ; +95->113 ; +95->114 ; +95->115 ; 96->114 ; -96->136 ; -96->45 ; -97->45 ; -97->13 ; -97->128 ; -98->13 ; -98->128 ; +96->115 ; +96->116 ; +97->115 ; +97->116 ; +97->117 ; +98->116 ; 98->117 ; -99->26 ; +98->118 ; +99->117 ; +99->118 ; 99->119 ; -99->120 ; -100->117 ; -100->26 ; +100->118 ; 100->119 ; +100->120 ; 101->119 ; 101->120 ; -101->113 ; +101->121 ; 102->120 ; -102->113 ; -102->17 ; -103->74 ; -103->53 ; -103->124 ; -104->53 ; +102->121 ; +102->122 ; +103->121 ; +103->122 ; +103->123 ; +104->122 ; +104->123 ; 104->124 ; -104->35 ; -105->20 ; -105->85 ; -105->87 ; +105->123 ; +105->124 ; +105->125 ; 106->124 ; -106->35 ; 106->125 ; +106->126 ; 107->125 ; +107->126 ; 107->127 ; -107->18 ; -108->84 ; -108->0 ; -109->34 ; -109->12 ; -109->43 ; -110->1 ; -110->115 ; -110->84 ; -111->84 ; -111->0 ; -112->127 ; -112->18 ; -112->129 ; -113->89 ; -113->137 ; -113->111 ; -114->18 ; -114->129 ; -114->131 ; -115->55 ; -116->84 ; -116->0 ; -117->110 ; -117->71 ; -117->68 ; -118->16 ; -118->20 ; -118->85 ; -119->68 ; -119->134 ; -119->89 ; -120->134 ; -120->89 ; -120->137 ; -121->39 ; -121->33 ; -121->58 ; -122->111 ; -122->138 ; -122->116 ; -123->135 ; -123->54 ; -123->15 ; -124->126 ; +108->126 ; +108->127 ; +108->128 ; +109->127 ; +109->128 ; +109->129 ; +110->128 ; +110->129 ; +110->130 ; +111->129 ; +111->130 ; +111->131 ; +112->130 ; +112->131 ; +112->132 ; +113->131 ; +113->132 ; +113->133 ; +114->132 ; +114->133 ; +114->134 ; +115->133 ; +115->134 ; +115->135 ; +116->134 ; +116->135 ; +116->136 ; +117->135 ; +117->136 ; +117->137 ; +118->136 ; +118->137 ; +118->138 ; +119->137 ; +119->138 ; +119->11 ; +120->138 ; +120->11 ; +120->10 ; +121->11 ; +121->10 ; +121->9 ; +122->10 ; +122->9 ; +122->8 ; +123->9 ; +123->8 ; +123->7 ; +124->8 ; 124->7 ; 124->6 ; +125->7 ; 125->6 ; -125->70 ; -125->4 ; -126->84 ; -126->0 ; -127->70 ; +125->5 ; +126->6 ; +126->5 ; +126->4 ; +127->5 ; 127->4 ; 127->3 ; -128->51 ; -128->110 ; -128->71 ; +128->4 ; +128->3 ; +128->2 ; 129->3 ; -129->108 ; 129->2 ; -130->80 ; -130->121 ; -130->46 ; -131->108 ; +130->3 ; +130->2 ; +131->3 ; 131->2 ; -131->5 ; -132->103 ; -132->104 ; -132->106 ; +132->3 ; +132->2 ; +133->3 ; 133->2 ; -133->5 ; -133->1 ; -134->84 ; -134->0 ; -135->132 ; -135->90 ; -135->92 ; -136->129 ; -136->131 ; -136->133 ; -137->84 ; -137->0 ; -138->84 ; -138->0 ; +134->3 ; +134->2 ; +135->3 ; +135->2 ; +136->3 ; +136->2 ; +137->3 ; +137->2 ; +138->3 ; +138->2 ; } diff --git a/tests/out/6.dot b/tests/out/6.dot index 3700b82..28324a6 100644 --- a/tests/out/6.dot +++ b/tests/out/6.dot @@ -1,836 +1,836 @@ digraph G { -0[label=241]; -1[label=240]; -2[label=239]; -3[label=237]; -4[label=235]; -5[label=231]; -6[label=230]; -7[label=229]; -8[label=226]; -9[label=224]; -10[label=222]; -11[label=221]; -12[label=216]; -13[label=212]; -14[label=210]; -15[label=209]; -16[label=205]; -17[label=203]; -18[label=201]; -19[label=200]; -20[label=197]; -21[label=192]; -22[label=191]; -23[label=190]; -24[label=234]; -25[label=187]; -26[label=186]; -27[label=183]; -28[label=236]; -29[label=182]; -30[label=178]; -31[label=176]; -32[label=174]; -33[label=173]; -34[label=180]; -35[label=172]; -36[label=170]; -37[label=168]; -38[label=167]; -39[label=166]; -40[label=164]; -41[label=162]; -42[label=161]; -43[label=219]; -44[label=160]; -45[label=158]; -46[label=157]; -47[label=223]; -48[label=155]; -49[label=154]; -50[label=152]; -51[label=151]; -52[label=150]; -53[label=208]; -54[label=149]; -55[label=148]; -56[label=147]; -57[label=145]; -58[label=188]; -59[label=144]; -60[label=143]; -61[label=138]; -62[label=137]; -63[label=134]; -64[label=132]; -65[label=130]; -66[label=213]; -67[label=129]; -68[label=133]; -69[label=127]; -70[label=126]; -71[label=54]; -72[label=211]; -73[label=159]; -74[label=50]; -75[label=48]; -76[label=46]; -77[label=37]; -78[label=238]; -79[label=96]; -80[label=49]; -81[label=218]; -82[label=53]; -83[label=225]; -84[label=61]; -85[label=103]; -86[label=214]; -87[label=163]; -88[label=111]; -89[label=55]; -90[label=62]; -91[label=184]; -92[label=31]; -93[label=194]; -94[label=57]; -95[label=227]; -96[label=56]; -97[label=79]; -98[label=29]; -99[label=139]; -100[label=99]; -101[label=41]; -102[label=28]; -103[label=39]; -104[label=11]; -105[label=90]; -106[label=18]; -107[label=9]; -108[label=36]; -109[label=108]; -110[label=76]; -111[label=22]; -112[label=85]; -113[label=198]; -114[label=8]; -115[label=35]; -116[label=217]; -117[label=40]; -118[label=67]; -119[label=38]; -120[label=17]; -121[label=175]; -122[label=95]; -123[label=30]; -124[label=169]; -125[label=58]; -126[label=115]; -127[label=16]; -128[label=156]; -129[label=106]; -130[label=228]; -131[label=42]; -132[label=5]; -133[label=4]; -134[label=52]; -135[label=140]; -136[label=End]; -137[label=7]; -138[label=65]; -139[label=10]; -140[label=27]; -141[label=6]; -142[label=Start]; -143[label=45]; -144[label=13]; -145[label=47]; -146[label=32]; -147[label=74]; -148[label=15]; -149[label=185]; -150[label=118]; -151[label=34]; -152[label=220]; -153[label=128]; -154[label=117]; -155[label=146]; -156[label=26]; -157[label=21]; -158[label=153]; -159[label=105]; -160[label=86]; -161[label=141]; -162[label=23]; -163[label=24]; -164[label=207]; -165[label=14]; -166[label=20]; -167[label=2]; -168[label=189]; -169[label=179]; +0[label=Start]; +1[label=End]; +2[label=241]; +3[label=240]; +4[label=239]; +5[label=238]; +6[label=237]; +7[label=236]; +8[label=235]; +9[label=234]; +10[label=233]; +11[label=232]; +12[label=231]; +13[label=230]; +14[label=229]; +15[label=228]; +16[label=227]; +17[label=226]; +18[label=225]; +19[label=224]; +20[label=223]; +21[label=222]; +22[label=221]; +23[label=220]; +24[label=219]; +25[label=218]; +26[label=217]; +27[label=216]; +28[label=215]; +29[label=214]; +30[label=213]; +31[label=212]; +32[label=211]; +33[label=210]; +34[label=209]; +35[label=208]; +36[label=207]; +37[label=206]; +38[label=205]; +39[label=204]; +40[label=203]; +41[label=202]; +42[label=201]; +43[label=200]; +44[label=199]; +45[label=198]; +46[label=197]; +47[label=196]; +48[label=195]; +49[label=194]; +50[label=193]; +51[label=192]; +52[label=191]; +53[label=190]; +54[label=189]; +55[label=188]; +56[label=187]; +57[label=186]; +58[label=185]; +59[label=184]; +60[label=183]; +61[label=182]; +62[label=181]; +63[label=180]; +64[label=179]; +65[label=178]; +66[label=177]; +67[label=176]; +68[label=175]; +69[label=174]; +70[label=173]; +71[label=172]; +72[label=171]; +73[label=170]; +74[label=169]; +75[label=168]; +76[label=167]; +77[label=166]; +78[label=165]; +79[label=164]; +80[label=163]; +81[label=162]; +82[label=161]; +83[label=160]; +84[label=159]; +85[label=158]; +86[label=157]; +87[label=156]; +88[label=155]; +89[label=154]; +90[label=153]; +91[label=152]; +92[label=151]; +93[label=150]; +94[label=149]; +95[label=148]; +96[label=147]; +97[label=146]; +98[label=145]; +99[label=144]; +100[label=143]; +101[label=142]; +102[label=141]; +103[label=138]; +104[label=140]; +105[label=139]; +106[label=137]; +107[label=136]; +108[label=135]; +109[label=134]; +110[label=133]; +111[label=132]; +112[label=131]; +113[label=130]; +114[label=129]; +115[label=128]; +116[label=59]; +117[label=58]; +118[label=57]; +119[label=56]; +120[label=55]; +121[label=54]; +122[label=53]; +123[label=52]; +124[label=51]; +125[label=50]; +126[label=49]; +127[label=48]; +128[label=47]; +129[label=46]; +130[label=45]; +131[label=44]; +132[label=43]; +133[label=42]; +134[label=41]; +135[label=40]; +136[label=39]; +137[label=38]; +138[label=37]; +139[label=36]; +140[label=35]; +141[label=34]; +142[label=33]; +143[label=32]; +144[label=31]; +145[label=30]; +146[label=13]; +147[label=12]; +148[label=11]; +149[label=10]; +150[label=3]; +151[label=9]; +152[label=2]; +153[label=8]; +154[label=7]; +155[label=1]; +156[label=6]; +157[label=5]; +158[label=4]; +159[label=14]; +160[label=15]; +161[label=16]; +162[label=17]; +163[label=18]; +164[label=19]; +165[label=20]; +166[label=21]; +167[label=22]; +168[label=23]; +169[label=24]; 170[label=25]; -171[label=193]; -172[label=84]; -173[label=60]; -174[label=136]; -175[label=63]; -176[label=12]; -177[label=64]; -178[label=204]; -179[label=142]; -180[label=66]; -181[label=181]; -182[label=120]; -183[label=70]; -184[label=68]; -185[label=177]; +171[label=26]; +172[label=27]; +173[label=28]; +174[label=29]; +175[label=60]; +176[label=61]; +177[label=62]; +178[label=63]; +179[label=64]; +180[label=65]; +181[label=66]; +182[label=67]; +183[label=68]; +184[label=69]; +185[label=70]; 186[label=71]; 187[label=72]; 188[label=73]; -189[label=233]; -190[label=215]; -191[label=59]; -192[label=75]; -193[label=165]; -194[label=77]; -195[label=78]; -196[label=199]; -197[label=81]; -198[label=80]; -199[label=82]; -200[label=206]; -201[label=83]; +189[label=74]; +190[label=75]; +191[label=76]; +192[label=77]; +193[label=78]; +194[label=79]; +195[label=80]; +196[label=81]; +197[label=82]; +198[label=83]; +199[label=84]; +200[label=85]; +201[label=86]; 202[label=87]; -203[label=171]; -204[label=88]; -205[label=44]; -206[label=89]; -207[label=91]; -208[label=131]; -209[label=19]; -210[label=116]; -211[label=232]; -212[label=122]; -213[label=92]; -214[label=102]; -215[label=93]; -216[label=135]; -217[label=124]; -218[label=98]; -219[label=43]; -220[label=100]; -221[label=196]; -222[label=101]; -223[label=3]; -224[label=104]; -225[label=33]; -226[label=107]; -227[label=109]; -228[label=125]; -229[label=195]; -230[label=110]; -231[label=97]; -232[label=112]; -233[label=202]; -234[label=1]; -235[label=113]; -236[label=69]; -237[label=114]; -238[label=119]; -239[label=51]; -240[label=94]; -241[label=121]; -242[label=123]; -0->136 ; -1->136 ; -2->136 ; -3->136 ; -4->136 ; -5->189 ; -5->24 ; -6->211 ; -6->189 ; -7->5 ; -7->211 ; -8->130 ; -8->7 ; -9->8 ; -9->95 ; -10->9 ; -10->83 ; -11->47 ; +203[label=88]; +204[label=89]; +205[label=90]; +206[label=91]; +207[label=92]; +208[label=93]; +209[label=94]; +210[label=95]; +211[label=96]; +212[label=97]; +213[label=98]; +214[label=99]; +215[label=100]; +216[label=101]; +217[label=102]; +218[label=103]; +219[label=104]; +220[label=105]; +221[label=106]; +222[label=107]; +223[label=108]; +224[label=109]; +225[label=110]; +226[label=111]; +227[label=112]; +228[label=113]; +229[label=114]; +230[label=115]; +231[label=116]; +232[label=117]; +233[label=118]; +234[label=119]; +235[label=120]; +236[label=121]; +237[label=122]; +238[label=123]; +239[label=124]; +240[label=125]; +241[label=126]; +242[label=127]; +0->2 ; +0->3 ; +0->4 ; +0->5 ; +0->6 ; +0->103 ; +0->150 ; +0->152 ; +0->155 ; +2->1 ; +3->1 ; +4->1 ; +5->1 ; +6->1 ; +7->1 ; +8->1 ; +9->1 ; +10->8 ; +10->7 ; 11->9 ; -12->81 ; -12->43 ; -13->86 ; -13->190 ; -14->13 ; -14->66 ; -15->72 ; +11->8 ; +12->10 ; +12->9 ; +13->11 ; +13->10 ; +14->12 ; +14->11 ; 15->13 ; -16->164 ; -16->53 ; -17->16 ; -17->200 ; -18->17 ; -18->178 ; -19->233 ; +15->12 ; +16->14 ; +16->13 ; +17->15 ; +17->14 ; +18->16 ; +18->15 ; 19->17 ; -20->196 ; -20->19 ; -21->93 ; -21->229 ; -22->171 ; -22->93 ; +19->16 ; +20->18 ; +20->17 ; +21->19 ; +21->18 ; +22->20 ; +22->19 ; 23->21 ; -23->171 ; -24->136 ; -25->168 ; +23->20 ; +24->22 ; +24->21 ; 25->23 ; -26->58 ; -26->168 ; -27->149 ; -27->26 ; -28->136 ; -29->91 ; -29->149 ; -30->34 ; -30->181 ; -31->30 ; -31->169 ; -32->31 ; -32->185 ; -33->121 ; +25->22 ; +26->24 ; +26->23 ; +27->25 ; +27->24 ; +28->26 ; +28->25 ; +29->27 ; +29->26 ; +30->28 ; +30->27 ; +31->29 ; +31->28 ; +32->30 ; +32->29 ; 33->31 ; -34->29 ; -34->27 ; +33->30 ; +34->32 ; +34->31 ; +35->33 ; 35->32 ; -35->121 ; -36->35 ; +36->34 ; 36->33 ; -37->36 ; -37->203 ; -38->124 ; +37->35 ; +37->34 ; 38->36 ; +38->35 ; 39->37 ; -39->124 ; -40->39 ; +39->36 ; 40->38 ; -41->40 ; -41->193 ; -42->87 ; +40->37 ; +41->39 ; +41->38 ; 42->40 ; -43->11 ; -43->10 ; +42->39 ; +43->41 ; +43->40 ; +44->42 ; 44->41 ; -44->87 ; -45->44 ; +45->43 ; 45->42 ; -46->73 ; 46->44 ; -47->83 ; -47->8 ; +46->43 ; +47->45 ; +47->44 ; 48->46 ; 48->45 ; -49->128 ; +49->47 ; 49->46 ; -50->49 ; 50->48 ; -51->158 ; +50->47 ; 51->49 ; +51->48 ; 52->50 ; -52->158 ; -53->14 ; -53->72 ; +52->49 ; +53->51 ; +53->50 ; +54->52 ; 54->51 ; -54->50 ; +55->53 ; 55->52 ; -55->51 ; 56->54 ; -56->52 ; -57->56 ; +56->53 ; 57->55 ; -58->23 ; -58->22 ; -59->155 ; +57->54 ; +58->56 ; +58->55 ; +59->57 ; 59->56 ; +60->58 ; 60->57 ; -60->155 ; -61->99 ; -61->135 ; -62->136 ; -63->136 ; -64->174 ; +61->59 ; +61->58 ; +62->60 ; +62->59 ; +63->61 ; +63->60 ; 64->62 ; -65->174 ; +64->61 ; +65->63 ; 65->62 ; -66->190 ; -66->12 ; -67->174 ; -67->62 ; -68->62 ; -69->174 ; -69->62 ; -70->174 ; -70->62 ; -71->187 ; -71->188 ; -71->147 ; -72->66 ; -72->86 ; -73->42 ; -73->41 ; -74->184 ; -74->236 ; -74->183 ; -75->180 ; -75->118 ; -75->184 ; -76->177 ; -76->138 ; -76->180 ; -77->89 ; -77->96 ; -77->94 ; -78->136 ; -79->237 ; -79->126 ; -79->210 ; -80->118 ; -80->184 ; -80->236 ; -81->152 ; -81->11 ; -82->186 ; -82->187 ; -82->188 ; -83->95 ; -83->130 ; -84->97 ; -84->198 ; -84->197 ; -85->241 ; -85->212 ; -85->242 ; -86->12 ; -86->116 ; -87->193 ; -87->39 ; -88->67 ; -88->65 ; -88->208 ; -89->188 ; -89->147 ; -89->192 ; -90->198 ; -90->197 ; -90->199 ; -91->26 ; -91->25 ; -92->80 ; -92->74 ; -92->239 ; -93->221 ; -93->20 ; -94->192 ; -94->110 ; -94->194 ; -95->7 ; -95->6 ; -96->147 ; -96->192 ; -96->110 ; -97->231 ; -97->218 ; -97->100 ; -98->145 ; -98->75 ; -98->80 ; -99->161 ; -99->179 ; -100->154 ; -100->150 ; -100->238 ; -101->191 ; -101->173 ; -101->84 ; -102->76 ; -102->145 ; -102->75 ; -103->94 ; -103->125 ; -103->191 ; -104->163 ; -104->170 ; -104->156 ; -105->109 ; -105->227 ; -105->230 ; -106->115 ; -106->108 ; -106->77 ; -107->166 ; -107->157 ; -108->71 ; -108->89 ; -108->96 ; -109->70 ; -109->69 ; -109->153 ; -110->240 ; -110->122 ; -110->79 ; -111->103 ; -111->117 ; -111->101 ; -112->85 ; -112->224 ; -112->159 ; -113->19 ; -113->18 ; +66->64 ; +66->63 ; +67->65 ; +67->64 ; +68->66 ; +68->65 ; +69->67 ; +69->66 ; +70->68 ; +70->67 ; +71->69 ; +71->68 ; +72->70 ; +72->69 ; +73->71 ; +73->70 ; +74->72 ; +74->71 ; +75->73 ; +75->72 ; +76->74 ; +76->73 ; +77->75 ; +77->74 ; +78->76 ; +78->75 ; +79->77 ; +79->76 ; +80->78 ; +80->77 ; +81->79 ; +81->78 ; +82->80 ; +82->79 ; +83->81 ; +83->80 ; +84->82 ; +84->81 ; +85->83 ; +85->82 ; +86->84 ; +86->83 ; +87->85 ; +87->84 ; +88->86 ; +88->85 ; +89->87 ; +89->86 ; +90->88 ; +90->87 ; +91->89 ; +91->88 ; +92->90 ; +92->89 ; +93->91 ; +93->90 ; +94->92 ; +94->91 ; +95->93 ; +95->92 ; +96->94 ; +96->93 ; +97->95 ; +97->94 ; +98->96 ; +98->95 ; +99->97 ; +99->96 ; +100->98 ; +100->97 ; +101->99 ; +101->98 ; +102->100 ; +102->99 ; +103->105 ; +103->104 ; +104->101 ; +104->100 ; +105->102 ; +105->101 ; +106->1 ; +107->1 ; +108->1 ; +109->1 ; +110->106 ; +111->107 ; +111->106 ; +112->107 ; +112->106 ; +113->107 ; +113->106 ; +114->107 ; 114->106 ; -114->209 ; -114->166 ; -115->82 ; -115->71 ; -115->89 ; -116->43 ; -116->152 ; -117->125 ; +115->107 ; +115->106 ; +116->192 ; +116->193 ; +116->194 ; 117->191 ; -117->173 ; -118->112 ; -118->160 ; -118->202 ; -119->96 ; -119->94 ; -119->125 ; -120->225 ; -120->151 ; -120->115 ; -121->185 ; -121->30 ; -122->235 ; -122->237 ; -122->126 ; -123->75 ; -123->80 ; -123->74 ; -124->203 ; -124->35 ; -125->110 ; -125->194 ; -125->195 ; -126->68 ; -126->63 ; -126->216 ; -127->146 ; -127->225 ; -127->151 ; -128->45 ; -128->73 ; -129->217 ; -129->228 ; -129->70 ; -130->6 ; -130->5 ; -131->173 ; -131->84 ; -131->90 ; +117->192 ; +117->193 ; +118->190 ; +118->191 ; +118->192 ; +119->189 ; +119->190 ; +119->191 ; +120->188 ; +120->189 ; +120->190 ; +121->187 ; +121->188 ; +121->189 ; +122->186 ; +122->187 ; +122->188 ; +123->185 ; +123->186 ; +123->187 ; +124->184 ; +124->185 ; +124->186 ; +125->183 ; +125->184 ; +125->185 ; +126->182 ; +126->183 ; +126->184 ; +127->181 ; +127->182 ; +127->183 ; +128->180 ; +128->181 ; +128->182 ; +129->179 ; +129->180 ; +129->181 ; +130->178 ; +130->179 ; +130->180 ; +131->177 ; +131->178 ; +131->179 ; 132->176 ; -132->144 ; -132->165 ; -133->139 ; -133->104 ; +132->177 ; +132->178 ; +133->175 ; 133->176 ; -134->183 ; -134->186 ; -134->187 ; -135->179 ; -135->60 ; -137->127 ; -137->120 ; -137->106 ; -138->201 ; -138->172 ; -138->112 ; -139->111 ; -139->162 ; -140->205 ; -140->143 ; -140->76 ; -141->165 ; -141->148 ; -141->127 ; -142->0 ; -142->1 ; -142->2 ; -142->3 ; -142->61 ; -142->78 ; -142->167 ; -142->223 ; -142->234 ; -143->175 ; -143->177 ; -143->138 ; -144->140 ; -144->102 ; -145->138 ; -145->180 ; -145->118 ; -146->74 ; -146->239 ; -146->134 ; -147->213 ; -147->215 ; -147->240 ; -148->123 ; -148->92 ; -148->146 ; -149->25 ; -149->58 ; -150->174 ; -150->62 ; -151->134 ; -151->82 ; -151->71 ; -152->10 ; -152->47 ; -153->174 ; -153->62 ; -154->216 ; -154->174 ; -154->62 ; -155->55 ; -155->54 ; -156->219 ; -156->205 ; -156->143 ; -157->119 ; -157->103 ; -157->117 ; -158->48 ; -158->128 ; -159->242 ; -159->217 ; -159->228 ; -160->224 ; -160->159 ; -160->129 ; -161->60 ; -161->59 ; -162->117 ; -162->101 ; -162->131 ; -163->101 ; -163->131 ; -163->219 ; -164->15 ; -164->14 ; -165->98 ; -165->123 ; -165->92 ; -166->77 ; -166->119 ; -166->103 ; -167->141 ; -167->137 ; -167->114 ; -168->22 ; -168->21 ; -169->181 ; -169->29 ; +133->177 ; +134->116 ; +134->175 ; +134->176 ; +135->117 ; +135->116 ; +135->175 ; +136->118 ; +136->117 ; +136->116 ; +137->119 ; +137->118 ; +137->117 ; +138->120 ; +138->119 ; +138->118 ; +139->121 ; +139->120 ; +139->119 ; +140->122 ; +140->121 ; +140->120 ; +141->123 ; +141->122 ; +141->121 ; +142->124 ; +142->123 ; +142->122 ; +143->125 ; +143->124 ; +143->123 ; +144->126 ; +144->125 ; +144->124 ; +145->127 ; +145->126 ; +145->125 ; +146->172 ; +146->173 ; +147->170 ; +147->171 ; +147->172 ; +148->169 ; +148->170 ; +148->171 ; +149->167 ; +149->168 ; +150->153 ; +150->151 ; +151->165 ; +151->166 ; +152->156 ; +152->154 ; +152->153 ; +153->163 ; +153->164 ; +153->165 ; +154->161 ; +154->162 ; +154->163 ; +155->158 ; +155->157 ; +155->156 ; +156->159 ; +156->160 ; +156->161 ; +157->147 ; +157->146 ; +157->159 ; +158->149 ; +158->148 ; +158->147 ; +159->174 ; +159->145 ; +159->144 ; +160->145 ; +160->144 ; +160->143 ; +161->143 ; +161->142 ; +161->141 ; +162->142 ; +162->141 ; +162->140 ; +163->140 ; +163->139 ; +163->138 ; +164->139 ; +164->138 ; +164->137 ; +165->138 ; +165->137 ; +165->136 ; +166->137 ; +166->136 ; +166->135 ; +167->136 ; +167->135 ; +167->134 ; +168->135 ; +168->134 ; +168->133 ; +169->134 ; +169->133 ; +169->132 ; +170->133 ; +170->132 ; 170->131 ; -170->219 ; -170->205 ; -171->229 ; -171->221 ; -172->214 ; -172->85 ; -172->224 ; -173->195 ; -173->97 ; -173->198 ; -174->136 ; -175->197 ; -175->199 ; -175->201 ; -176->170 ; -176->156 ; -176->140 ; -177->199 ; -177->201 ; -177->172 ; -178->200 ; -178->164 ; -179->59 ; -179->57 ; -180->172 ; -180->112 ; -180->160 ; -181->27 ; -181->91 ; -182->174 ; -182->62 ; -183->204 ; -183->206 ; -183->105 ; -184->160 ; +171->132 ; +171->131 ; +171->130 ; +172->131 ; +172->130 ; +172->129 ; +173->129 ; +173->128 ; +173->127 ; +174->128 ; +174->127 ; +174->126 ; +175->193 ; +175->194 ; +175->195 ; +176->194 ; +176->195 ; +176->196 ; +177->195 ; +177->196 ; +177->197 ; +178->196 ; +178->197 ; +178->198 ; +179->197 ; +179->198 ; +179->199 ; +180->198 ; +180->199 ; +180->200 ; +181->199 ; +181->200 ; +181->201 ; +182->200 ; +182->201 ; +182->202 ; +183->201 ; +183->202 ; +183->203 ; 184->202 ; +184->203 ; 184->204 ; -185->169 ; -185->34 ; +185->203 ; +185->204 ; +185->205 ; +186->204 ; +186->205 ; 186->206 ; -186->105 ; -186->207 ; -187->105 ; +187->205 ; +187->206 ; 187->207 ; -187->213 ; +188->206 ; 188->207 ; -188->213 ; -188->215 ; -189->4 ; -189->28 ; -190->116 ; -190->81 ; -191->194 ; -191->195 ; -191->97 ; -192->215 ; -192->240 ; -192->122 ; -193->38 ; -193->37 ; -194->122 ; -194->79 ; -194->231 ; -195->79 ; -195->231 ; -195->218 ; -196->18 ; -196->233 ; -197->100 ; -197->220 ; -197->222 ; +188->208 ; +189->207 ; +189->208 ; +189->209 ; +190->208 ; +190->209 ; +190->210 ; +191->209 ; +191->210 ; +191->211 ; +192->210 ; +192->211 ; +192->212 ; +193->211 ; +193->212 ; +193->213 ; +194->212 ; +194->213 ; +194->214 ; +195->213 ; +195->214 ; +195->215 ; +196->214 ; +196->215 ; +196->216 ; +197->215 ; +197->216 ; +197->217 ; +198->216 ; +198->217 ; 198->218 ; -198->100 ; -198->220 ; -199->220 ; -199->222 ; -199->214 ; -200->53 ; -200->15 ; -201->222 ; -201->214 ; -201->85 ; -202->159 ; -202->129 ; -202->226 ; -203->33 ; -203->32 ; -204->129 ; -204->226 ; -204->109 ; -205->90 ; -205->175 ; -205->177 ; +199->217 ; +199->218 ; +199->219 ; +200->218 ; +200->219 ; +200->220 ; +201->219 ; +201->220 ; +201->221 ; +202->220 ; +202->221 ; +202->222 ; +203->221 ; +203->222 ; +203->223 ; +204->222 ; +204->223 ; +204->224 ; +205->223 ; +205->224 ; +205->225 ; +206->224 ; +206->225 ; 206->226 ; -206->109 ; -206->227 ; +207->225 ; +207->226 ; 207->227 ; -207->230 ; -207->88 ; -208->174 ; -208->62 ; -209->108 ; -209->77 ; -209->119 ; -210->63 ; -210->216 ; -210->174 ; -211->24 ; -211->4 ; -212->174 ; -212->62 ; -213->230 ; -213->88 ; +208->226 ; +208->227 ; +208->228 ; +209->227 ; +209->228 ; +209->229 ; +210->228 ; +210->229 ; +210->230 ; +211->229 ; +211->230 ; +211->231 ; +212->230 ; +212->231 ; +212->232 ; +213->231 ; 213->232 ; -214->182 ; -214->241 ; -214->212 ; -215->88 ; -215->232 ; +213->233 ; +214->232 ; +214->233 ; +214->234 ; +215->233 ; +215->234 ; 215->235 ; -216->136 ; -217->174 ; -217->62 ; -218->210 ; -218->154 ; -218->150 ; -219->84 ; -219->90 ; -219->175 ; -220->150 ; +216->234 ; +216->235 ; +216->236 ; +217->235 ; +217->236 ; +217->237 ; +218->236 ; +218->237 ; +218->238 ; +219->237 ; +219->238 ; +219->239 ; 220->238 ; -220->182 ; -221->113 ; -221->196 ; -222->238 ; -222->182 ; +220->239 ; +220->240 ; +221->239 ; +221->240 ; +221->241 ; +222->240 ; 222->241 ; -223->114 ; -223->107 ; -224->212 ; +222->242 ; +223->241 ; +223->242 ; +223->115 ; 224->242 ; -224->217 ; -225->239 ; -225->134 ; -225->82 ; -226->228 ; -226->70 ; -226->69 ; -227->69 ; -227->153 ; -227->67 ; -228->174 ; -228->62 ; -229->20 ; -229->113 ; -230->153 ; -230->67 ; -230->65 ; -231->126 ; -231->210 ; -231->154 ; -232->65 ; -232->208 ; -232->64 ; -233->178 ; -233->16 ; -234->133 ; -234->132 ; -234->141 ; -235->208 ; -235->64 ; -235->68 ; -236->202 ; -236->204 ; -236->206 ; -237->64 ; -237->68 ; -237->63 ; -238->174 ; -238->62 ; -239->236 ; -239->183 ; -239->186 ; -240->232 ; -240->235 ; -240->237 ; -241->174 ; -241->62 ; -242->174 ; -242->62 ; +224->115 ; +224->114 ; +225->115 ; +225->114 ; +225->113 ; +226->114 ; +226->113 ; +226->112 ; +227->113 ; +227->112 ; +227->111 ; +228->112 ; +228->111 ; +228->110 ; +229->111 ; +229->110 ; +229->109 ; +230->110 ; +230->109 ; +230->108 ; +231->109 ; +231->108 ; +231->107 ; +232->108 ; +232->107 ; +232->106 ; +233->107 ; +233->106 ; +234->107 ; +234->106 ; +235->107 ; +235->106 ; +236->107 ; +236->106 ; +237->107 ; +237->106 ; +238->107 ; +238->106 ; +239->107 ; +239->106 ; +240->107 ; +240->106 ; +241->107 ; +241->106 ; +242->107 ; +242->106 ; } diff --git a/tests/out/7.dot b/tests/out/7.dot index 7e289d0..ff9c5a8 100644 --- a/tests/out/7.dot +++ b/tests/out/7.dot @@ -1,13 +1,13 @@ digraph G { -0[label=4]; -1[label=3]; -2[label=1]; -3[label=2]; -4[label=End]; -5[label=Start]; +0[label=Start]; +1[label=End]; +2[label=4]; +3[label=3]; +4[label=1]; +5[label=2]; 0->4 ; -1->0 ; -2->3 ; -3->1 ; -5->2 ; +2->1 ; +3->2 ; +4->5 ; +5->3 ; } diff --git a/tests/out/8.dot b/tests/out/8.dot index 3eca985..6511071 100644 --- a/tests/out/8.dot +++ b/tests/out/8.dot @@ -1,88 +1,88 @@ digraph G { -0[label=29]; -1[label=28]; -2[label=11]; -3[label=18]; -4[label=4]; -5[label=9]; -6[label=1]; -7[label=22]; -8[label=8]; -9[label=17]; -10[label=19]; -11[label=30]; -12[label=6]; -13[label=3]; -14[label=16]; +0[label=Start]; +1[label=End]; +2[label=30]; +3[label=13]; +4[label=12]; +5[label=11]; +6[label=10]; +7[label=4]; +8[label=9]; +9[label=3]; +10[label=8]; +11[label=2]; +12[label=7]; +13[label=1]; +14[label=6]; 15[label=5]; -16[label=End]; -17[label=7]; -18[label=10]; -19[label=27]; -20[label=Start]; -21[label=13]; -22[label=15]; -23[label=12]; -24[label=14]; -25[label=26]; -26[label=20]; -27[label=21]; -28[label=23]; -29[label=24]; -30[label=2]; -31[label=25]; +16[label=14]; +17[label=15]; +18[label=16]; +19[label=17]; +20[label=18]; +21[label=19]; +22[label=20]; +23[label=21]; +24[label=22]; +25[label=23]; +26[label=24]; +27[label=25]; +28[label=26]; +29[label=27]; +30[label=28]; +31[label=29]; +0->7 ; +0->9 ; 0->11 ; -1->11 ; -2->22 ; -2->14 ; -3->7 ; -3->28 ; -4->8 ; -4->5 ; -5->21 ; -5->24 ; -6->15 ; -6->12 ; -7->25 ; -7->19 ; -8->23 ; -8->21 ; -9->27 ; -9->7 ; -10->28 ; -10->29 ; -11->16 ; -12->18 ; -12->2 ; -13->17 ; -13->8 ; -14->26 ; -14->27 ; -15->18 ; -17->2 ; -17->23 ; +0->13 ; +2->1 ; +3->19 ; +3->20 ; +4->18 ; +4->19 ; +5->17 ; +5->18 ; +6->17 ; +7->10 ; +7->8 ; +8->3 ; +8->16 ; +9->12 ; +9->10 ; +10->4 ; +10->3 ; +11->14 ; +11->12 ; +12->5 ; +12->4 ; +13->15 ; +13->14 ; +14->6 ; +14->5 ; +15->6 ; +16->20 ; +16->21 ; +17->22 ; 18->22 ; -19->11 ; -20->4 ; -20->6 ; -20->13 ; -20->30 ; -21->9 ; -21->3 ; -22->26 ; -23->14 ; -23->9 ; -24->3 ; -24->10 ; -25->11 ; +18->23 ; +19->23 ; +19->24 ; +20->24 ; +20->25 ; +21->25 ; +21->26 ; +22->27 ; +23->27 ; +23->28 ; +24->28 ; +24->29 ; +25->29 ; +25->30 ; +26->30 ; 26->31 ; -27->31 ; -27->25 ; -28->19 ; -28->1 ; -29->1 ; -29->0 ; -30->12 ; -30->17 ; -31->11 ; +27->2 ; +28->2 ; +29->2 ; +30->2 ; +31->2 ; } diff --git a/tests/unit_tests.cc b/tests/unit_tests.cc new file mode 100644 index 0000000..eaf7c03 --- /dev/null +++ b/tests/unit_tests.cc @@ -0,0 +1,119 @@ +#include + +#include +#include +#include + +#include "graphs/graph.hh" + +class GraphTest : public testing::Test {}; + +TEST_F(GraphTest, TopologicalSort) { + graph::Graph g0; + std::vector o0; + ASSERT_EQ(g0.topologicalSort(), o0); + + graph::Graph g1 = {{42, {}}}; + std::vector o1 = {42}; + ASSERT_EQ(g1.topologicalSort(), o1); + + graph::Graph g2 = {{1, {2}}}; + std::vector o2 = {1, 2}; + ASSERT_EQ(g2.topologicalSort(), o2); + + graph::Graph g3{{1, {2, 3, 4}}, {2, {3, 4}}, {3, {4}}}; + std::vector o3 = {1, 2, 3, 4}; + ASSERT_EQ(g3.topologicalSort(), o3); + + graph::Graph g4 = { + {1, {2}}, {2, {3}}, {3, {4}}, + {4, {5}}, {5, {6, 7}}, {6, {7}}, + {7, {8, 10}}, {8, {9}}, {9, {10}}, + {10, {11, 12}}, {11, {12, 16}}, {12, {13}}, + {13, {14}}, {14, {15, 17}}, {15, {16, 17}}, + {16, {17}}, {17, {18, 20}}, {18, {19}}, + {19, {20}}, {20, {21, 22}}, {21, {22}}, + {22, {23}}, {23, {24, 26}}, {24, {25}}, + {25, {26, 27}}, {26, {27}}, {27, {28}}, + {28, {29}}, {29, {30, 32}}, {30, {31, 32}}, + {31, {32}}, {32, {33}}, {33, {34}}, + {34, {35, 37}}, {35, {36, 37}}, {36, {37}}, + {37, {38, 40}}, {38, {39}}, {39, {40}}, + {40, {41, 42}}, {41, {42}}, {42, {43}}, + {43, {44}}, {44, {45, 47}}, {45, {46, 47}}, + {46, {47}}, {47, {48}}, {48, {49}}, + {49, {50, 52}}, {50, {51, 52}}, {51, {52}}, + {52, {53}}, {53, {54}}, {54, {55}}, + {55, {56, 57, 60}}, {56, {57, 59}}, {57, {58}}, + {58, {59}}, {59, {60}}, {60, {61, 62}}, + {61, {62}}, {62, {63}}, {63, {64, 66}}, + {64, {65}}, {65, {66, 67}}, {66, {67}}, + {67, {68, 70}}, {68, {69}}, {69, {70}}, + {70, {71, 72}}, {71, {72}}, {72, {73}}, + {73, {74}}, {74, {75, 77}}, {75, {76, 77}}, + {76, {77}}, {77, {78, 80}}, {78, {79}}, + {79, {80}}, {80, {81, 82}}, {81, {82}}, + {82, {83}}, {83, {84}}, {84, {85, 87}}, + {85, {86, 87}}, {86, {87}}, {87, {88, 90}}, + {88, {89}}, {89, {90}}, {90, {91, 92}}, + {91, {92}}, {92, {93}}, {93, {94}}, + {94, {95, 97}}, {95, {96, 97}}, {96, {97}}, + {97, {98, 100}}, {98, {99}}, {99, {100}}, + {100, {101, 102}}, {101, {102}}, {102, {103}}, + {103, {104}}, {104, {105, 107}}, {105, {106, 107}}, + {106, {107}}, {107, {108, 110}}, {108, {109}}, + {109, {110}}, {110, {111, 112}}, {111, {112}}, + {112, {113}}, {113, {114}}, {114, {115, 117}}, + {115, {116, 117}}, {116, {117}}, {117, {118, 120}}, + {118, {119}}, {119, {120}}, {120, {121, 122}}, + {121, {122}}, {122, {123}}, {123, {124}}, + {124, {125, 127}}, {125, {126, 127}}, {126, {127}}, + {127, {128, 130}}, {128, {129}}, {129, {130}}, + {130, {131, 132}}, {131, {132}}, {132, {133}}, + {133, {134}}, {134, {135, 137}}, {135, {136, 137}}, + {136, {137}}, {137, {138, 140}}, {138, {139}}, + {139, {140}}, {140, {141, 142}}, {141, {142}}, + {142, {143}}, {143, {144}}, {144, {145, 147}}, + {145, {146, 147}}, {146, {147}}, {147, {148, 150}}, + {148, {149}}, {149, {150}}, {150, {151, 152}}, + {151, {152}}, {152, {153}}, {153, {154}}, + {154, {155, 157}}, {155, {156, 157}}, {156, {157}}, + {157, {158, 160}}, {158, {159}}, {159, {160}}, + {160, {161, 162}}, {161, {162}}, {162, {163}}, + {163, {164}}, {164, {165, 167}}, {165, {166, 167}}, + {166, {167}}, {167, {168, 170}}, {168, {169}}, + {169, {170}}, {170, {171, 172}}, {171, {172}}, + {172, {173}}, {173, {174}}, {174, {175, 177}}, + {175, {176, 177}}, {176, {177}}, {177, {178, 180}}, + {178, {179}}, {179, {180}}, {180, {181, 182}}, + {181, {182}}, {182, {183}}, {183, {184}}, + {184, {185, 187}}, {185, {186, 187}}, {186, {187}}, + {187, {188, 190}}, {188, {189}}, {189, {190}}, + {190, {191, 192}}, {191, {192}}, {192, {193}}, + {193, {194}}, {194, {195}}, {195, {196, 197}}, + {196, {197, 199}}, {197, {198}}, {198, {199, 203}}, + {199, {200}}, {200, {201, 202}}, {201, {202}}, + {202, {203}}, {203, {204}}, {204, {205}}, + {205, {}}}; + std::vector o4 = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, + 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, 199, 200, 201, 202, 203, 204, 205}; + ASSERT_EQ(g4.topologicalSort(), o4); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}