From 148a088dd69028e18903fffbbdc0917cb421b2ae Mon Sep 17 00:00:00 2001 From: hitonanode <32937551+hitonanode@users.noreply.github.com> Date: Sun, 14 Mar 2021 20:51:13 +0900 Subject: [PATCH 1/2] Graphviz dump for maxflow, shortestpath --- combinatorial_opt/maxflow.hpp | 15 +++++++++++++++ graph/bellman_ford.hpp | 27 --------------------------- graph/shortest_path.hpp | 13 +++++++++++++ graph/test/bellman_ford.test.cpp | 11 ++--------- 4 files changed, 30 insertions(+), 36 deletions(-) delete mode 100644 graph/bellman_ford.hpp diff --git a/combinatorial_opt/maxflow.hpp b/combinatorial_opt/maxflow.hpp index e3f18213..e195288e 100644 --- a/combinatorial_opt/maxflow.hpp +++ b/combinatorial_opt/maxflow.hpp @@ -2,7 +2,9 @@ #include #include +#include #include +#include #include // CUT begin @@ -145,6 +147,19 @@ template struct mf_graph { return visited; } + void dump_graphviz(std::string filename = "maxflow") const { + std::ofstream ss(filename + ".DOT"); + ss << "digraph{\n"; + for (int i = 0; i < _n; i++) { + for (const auto &e : g[i]) { + if (e.cap > 0) ss << i << "->" << e.to << "[label=" << e.cap << "];\n"; + } + } + ss << "}\n"; + ss.close(); + return; + } + int _n; struct _edge { int to, rev; diff --git a/graph/bellman_ford.hpp b/graph/bellman_ford.hpp deleted file mode 100644 index 52128f36..00000000 --- a/graph/bellman_ford.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include -#include -using namespace std; - -// CUT begin -using wedges = vector>>; // (to, weight) -constexpr long long INF = 1e17; -vector bellman_ford(int s, const wedges &w, int T) { - int N = w.size(); - vector d(N, INF); - d[s] = 0; - for (int l = 0; l < T; l++) { - bool upd = false; - for (int i = 0; i < N; i++) { - if (d[i] >= INF) continue; - for (auto pa : w[i]) { - if (d[pa.first] > d[i] + pa.second) { - d[pa.first] = d[i] + pa.second; - upd = true; - } - } - } - if (!upd) break; - } - return d; -} diff --git a/graph/shortest_path.hpp b/graph/shortest_path.hpp index 8c6361e5..cc2ba2ab 100644 --- a/graph/shortest_path.hpp +++ b/graph/shortest_path.hpp @@ -1,9 +1,11 @@ #pragma once #include #include +#include #include #include #include +#include #include #include @@ -160,4 +162,15 @@ template ::max() / 2, int INVALID = - } } } + + void dump_graphviz(std::string filename = "shortest_path") const { + std::ofstream ss(filename + ".DOT"); + ss << "digraph{\n"; + for (int i = 0; i < V; i++) { + for (const auto &e : to[i]) ss << i << "->" << e.first << "[label=" << e.second << "];\n"; + } + ss << "}\n"; + ss.close(); + return; + } }; diff --git a/graph/test/bellman_ford.test.cpp b/graph/test/bellman_ford.test.cpp index 0b5385fc..e9686988 100644 --- a/graph/test/bellman_ford.test.cpp +++ b/graph/test/bellman_ford.test.cpp @@ -1,23 +1,18 @@ -#include "../bellman_ford.hpp" #include "../shortest_path.hpp" #include #include #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B" - -wedges e; +using namespace std; int main() { int V, E, r; cin >> V >> E >> r; ShortestPath graph(V); - e.resize(V); for (int i = 0; i < E; i++) { int s, t, d; cin >> s >> t >> d; - e[s].emplace_back(t, d); graph.add_edge(s, t, d); } - vector ret = bellman_ford(r, e, V); if (!graph.BellmanFord(r, V + 1)) { puts("NEGATIVE CYCLE"); @@ -25,11 +20,9 @@ int main() { } for (int i = 0; i < V; i++) { - if (graph.dist[i] >= INF) { - assert(ret[i] == INF); + if (graph.dist[i] >= 1LL << 50) { puts("INF"); } else { - assert(ret[i] == graph.dist[i]); printf("%lld\n", graph.dist[i]); } } From 5d4c3ab0fac039639afebe285234a0e8fee460ce Mon Sep 17 00:00:00 2001 From: GitHub Date: Sun, 14 Mar 2021 11:56:41 +0000 Subject: [PATCH 2/2] [auto-verifier] verify commit 148a088dd69028e18903fffbbdc0917cb421b2ae --- .verify-helper/timestamps.remote.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.verify-helper/timestamps.remote.json b/.verify-helper/timestamps.remote.json index 9857ce6d..10afa728 100644 --- a/.verify-helper/timestamps.remote.json +++ b/.verify-helper/timestamps.remote.json @@ -1,7 +1,7 @@ { "combinatorial_opt/test/assignment_problem.test.cpp": "2020-12-14 02:27:33 +0900", "combinatorial_opt/test/bflow_ns.test.cpp": "2021-02-27 20:43:19 +0900", -"combinatorial_opt/test/maxflow.test.cpp": "2020-12-14 02:27:33 +0900", +"combinatorial_opt/test/maxflow.test.cpp": "2021-03-14 20:51:13 +0900", "combinatorial_opt/test/mincostflow.test.cpp": "2021-02-27 23:24:10 +0900", "combinatorial_opt/test/simplex.easy.test.cpp": "2021-02-28 16:53:36 +0900", "combinatorial_opt/test/simplex.maxflow.test.cpp": "2021-02-28 16:53:36 +0900", @@ -49,7 +49,7 @@ "geometry/test/sort_by_argument.test.cpp": "2020-11-18 20:25:12 +0900", "graph/test/2sat_solver.test.cpp": "2021-01-01 16:38:37 +0900", "graph/test/articulation_points.test.cpp": "2020-11-21 18:08:42 +0900", -"graph/test/bellman_ford.test.cpp": "2021-02-21 15:19:18 +0900", +"graph/test/bellman_ford.test.cpp": "2021-03-14 20:51:13 +0900", "graph/test/bipartite_matching(slow).test.cpp": "2020-11-21 18:08:42 +0900", "graph/test/bipartite_matching.test.cpp": "2020-11-21 18:08:42 +0900", "graph/test/bridge.test.cpp": "2020-11-21 18:08:42 +0900", @@ -57,14 +57,14 @@ "graph/test/general_matching.test.cpp": "2021-01-10 04:11:55 +0900", "graph/test/incremental-bridge-connectivity.test.cpp": "2020-11-21 18:08:42 +0900", "graph/test/maximum_independent_set.test.cpp": "2020-11-21 18:08:42 +0900", -"graph/test/shortest_cycle.test.cpp": "2021-02-21 15:19:18 +0900", -"graph/test/shortest_path.test.cpp": "2021-02-21 15:19:18 +0900", -"graph/test/spfa.test.cpp": "2021-02-21 15:19:18 +0900", +"graph/test/shortest_cycle.test.cpp": "2021-03-14 20:51:13 +0900", +"graph/test/shortest_path.test.cpp": "2021-03-14 20:51:13 +0900", +"graph/test/spfa.test.cpp": "2021-03-14 20:51:13 +0900", "graph/test/strongly_connected_components.test.cpp": "2021-01-01 16:38:37 +0900", "graph/test/strongly_connected_components_bitset.test.cpp": "2020-11-21 18:08:42 +0900", "graph/test/topological_sort.test.cpp": "2021-01-01 16:38:37 +0900", "graph/test/two-edge-connected-components.test.cpp": "2020-11-21 18:08:42 +0900", -"graph/test/warshallfloyd.test.cpp": "2021-02-21 15:19:18 +0900", +"graph/test/warshallfloyd.test.cpp": "2021-03-14 20:51:13 +0900", "linear_algebra_matrix/test/det_of_sparse_matrix.test.cpp": "2021-01-10 04:11:55 +0900", "linear_algebra_matrix/test/linalg_bitset.test.cpp": "2020-11-18 21:29:24 +0900", "linear_algebra_matrix/test/linalg_ll_det.test.cpp": "2020-11-18 20:06:08 +0900", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy