DirectedGraph

romophic-library

用途

重み付き有向グラフを扱う.

使い方

宣言

1
DirectedGraph g(n);

重み付き有向パスの追加

1
g.add(パス始点, パス終点, 重み);

実装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class DirectedGraph {
public:
  struct Edge {
    int to, cost;
  };
  const int n;
  vector<vector<Edge>> g;
  DirectedGraph(int _n) : n(_n), g(_n) {}
  void add(int s, int t, int cost) {
    g[s].push_back({t, cost});
  }
};

Depended on

Licensed under CC BY-NC-ND 4.0
All rights reserved.
Built with Hugo
Theme Stack is designed by Jimmy