Index: lemon/capacity_scaling.h
===================================================================
--- lemon/capacity_scaling.h	(revision 2623)
+++ lemon/capacity_scaling.h	(revision 2629)
@@ -255,23 +255,26 @@
                      const CostMap &cost,
                      const SupplyMap &supply ) :
-      _graph(graph), _lower(&lower), _capacity(graph), _cost(cost),
-      _supply(graph), _flow(NULL), _local_flow(false),
+      _graph(graph), _lower(&lower), _capacity(capacity), _cost(cost),
+      _supply(supply), _flow(NULL), _local_flow(false),
       _potential(NULL), _local_potential(false),
-      _res_cap(graph), _excess(graph), _pred(graph), _dijkstra(NULL)
+      _res_cap(capacity), _excess(supply), _pred(graph), _dijkstra(NULL)
     {
-      // Removing non-zero lower bounds
-      _capacity = subMap(capacity, lower);
-      _res_cap = _capacity;
+      // Check the sum of supply values
       Supply sum = 0;
-      for (NodeIt n(_graph); n != INVALID; ++n) {
-        Supply s = supply[n];
-        for (InEdgeIt e(_graph, n); e != INVALID; ++e)
-          s += lower[e];
-        for (OutEdgeIt e(_graph, n); e != INVALID; ++e)
-          s -= lower[e];
-        _supply[n] = s;
-        sum += s;
-      }
+      for (NodeIt n(_graph); n != INVALID; ++n) sum += _supply[n];
       _valid_supply = sum == 0;
+
+      // Remove non-zero lower bounds
+      typename LowerMap::Value lcap;
+      for (EdgeIt e(_graph); e != INVALID; ++e) {
+        if ((lcap = lower[e]) != 0) {
+          _capacity[e] -= lcap;
+          _res_cap[e] -= lcap;
+          _supply[_graph.source(e)] -= lcap;
+          _supply[_graph.target(e)] += lcap;
+          _excess[_graph.source(e)] -= lcap;
+          _excess[_graph.target(e)] += lcap;
+        }
+      }
     }
 
@@ -291,7 +294,7 @@
       _supply(supply), _flow(NULL), _local_flow(false),
       _potential(NULL), _local_potential(false),
-      _res_cap(capacity), _excess(graph), _pred(graph), _dijkstra(NULL)
+      _res_cap(capacity), _excess(supply), _pred(graph), _dijkstra(NULL)
     {
-      // Checking the sum of supply values
+      // Check the sum of supply values
       Supply sum = 0;
       for (NodeIt n(_graph); n != INVALID; ++n) sum += _supply[n];
@@ -317,21 +320,22 @@
                      Node s, Node t,
                      Supply flow_value ) :
-      _graph(graph), _lower(&lower), _capacity(graph), _cost(cost),
-      _supply(graph), _flow(NULL), _local_flow(false),
+      _graph(graph), _lower(&lower), _capacity(capacity), _cost(cost),
+      _supply(graph, 0), _flow(NULL), _local_flow(false),
       _potential(NULL), _local_potential(false),
-      _res_cap(graph), _excess(graph), _pred(graph), _dijkstra(NULL)
+      _res_cap(capacity), _excess(graph, 0), _pred(graph), _dijkstra(NULL)
     {
-      // Removing non-zero lower bounds
-      _capacity = subMap(capacity, lower);
-      _res_cap = _capacity;
-      for (NodeIt n(_graph); n != INVALID; ++n) {
-        Supply sum = 0;
-        if (n == s) sum =  flow_value;
-        if (n == t) sum = -flow_value;
-        for (InEdgeIt e(_graph, n); e != INVALID; ++e)
-          sum += lower[e];
-        for (OutEdgeIt e(_graph, n); e != INVALID; ++e)
-          sum -= lower[e];
-        _supply[n] = sum;
+      // Remove non-zero lower bounds
+      _supply[s] = _excess[s] =  flow_value;
+      _supply[t] = _excess[t] = -flow_value;
+      typename LowerMap::Value lcap;
+      for (EdgeIt e(_graph); e != INVALID; ++e) {
+        if ((lcap = lower[e]) != 0) {
+          _capacity[e] -= lcap;
+          _res_cap[e] -= lcap;
+          _supply[_graph.source(e)] -= lcap;
+          _supply[_graph.target(e)] += lcap;
+          _excess[_graph.source(e)] -= lcap;
+          _excess[_graph.target(e)] += lcap;
+        }
       }
       _valid_supply = true;
@@ -357,8 +361,8 @@
       _supply(graph, 0), _flow(NULL), _local_flow(false),
       _potential(NULL), _local_potential(false),
-      _res_cap(capacity), _excess(graph), _pred(graph), _dijkstra(NULL)
+      _res_cap(capacity), _excess(graph, 0), _pred(graph), _dijkstra(NULL)
     {
-      _supply[s] =  flow_value;
-      _supply[t] = -flow_value;
+      _supply[s] = _excess[s] =  flow_value;
+      _supply[t] = _excess[t] = -flow_value;
       _valid_supply = true;
     }
@@ -498,5 +502,4 @@
       for (EdgeIt e(_graph); e != INVALID; ++e) (*_flow)[e] = 0;
       for (NodeIt n(_graph); n != INVALID; ++n) (*_potential)[n] = 0;
-      _excess = _supply;
 
       _dijkstra = new ResidualDijkstra( _graph, *_flow, _res_cap, _cost,
Index: lemon/cost_scaling.h
===================================================================
--- lemon/cost_scaling.h	(revision 2625)
+++ lemon/cost_scaling.h	(revision 2629)
@@ -201,22 +201,22 @@
                  const CostMap &cost,
                  const SupplyMap &supply ) :
-      _graph(graph), _lower(&lower), _capacity(graph), _orig_cost(cost),
-      _cost(graph), _supply(graph), _flow(NULL), _local_flow(false),
+      _graph(graph), _lower(&lower), _capacity(capacity), _orig_cost(cost),
+      _cost(graph), _supply(supply), _flow(NULL), _local_flow(false),
       _potential(NULL), _local_potential(false), _res_cost(_cost),
       _res_graph(NULL), _red_cost(NULL), _excess(graph, 0)
     {
+      // Check the sum of supply values
+      Supply sum = 0;
+      for (NodeIt n(_graph); n != INVALID; ++n) sum += _supply[n];
+      _valid_supply = sum == 0;
+
       // Remove non-zero lower bounds
-      _capacity = subMap(capacity, lower);
-      Supply sum = 0;
-      for (NodeIt n(_graph); n != INVALID; ++n) {
-        Supply s = supply[n];
-        for (InEdgeIt e(_graph, n); e != INVALID; ++e)
-          s += lower[e];
-        for (OutEdgeIt e(_graph, n); e != INVALID; ++e)
-          s -= lower[e];
-        _supply[n] = s;
-        sum += s;
-      }
-      _valid_supply = sum == 0;
+      for (EdgeIt e(_graph); e != INVALID; ++e) {
+        if (lower[e] != 0) {
+          _capacity[e] -= lower[e];
+          _supply[_graph.source(e)] -= lower[e];
+          _supply[_graph.target(e)] += lower[e];
+        }
+      }
     }
 
@@ -262,20 +262,18 @@
                  Node s, Node t,
                  Supply flow_value ) :
-      _graph(graph), _lower(&lower), _capacity(graph), _orig_cost(cost),
-      _cost(graph), _supply(graph), _flow(NULL), _local_flow(false),
+      _graph(graph), _lower(&lower), _capacity(capacity), _orig_cost(cost),
+      _cost(graph), _supply(graph, 0), _flow(NULL), _local_flow(false),
       _potential(NULL), _local_potential(false), _res_cost(_cost),
       _res_graph(NULL), _red_cost(NULL), _excess(graph, 0)
     {
-      // Remove nonzero lower bounds
-      _capacity = subMap(capacity, lower);
-      for (NodeIt n(_graph); n != INVALID; ++n) {
-        Supply sum = 0;
-        if (n == s) sum =  flow_value;
-        if (n == t) sum = -flow_value;
-        for (InEdgeIt e(_graph, n); e != INVALID; ++e)
-          sum += lower[e];
-        for (OutEdgeIt e(_graph, n); e != INVALID; ++e)
-          sum -= lower[e];
-        _supply[n] = sum;
+      // Remove non-zero lower bounds
+      _supply[s] =  flow_value;
+      _supply[t] = -flow_value;
+      for (EdgeIt e(_graph); e != INVALID; ++e) {
+        if (lower[e] != 0) {
+          _capacity[e] -= lower[e];
+          _supply[_graph.source(e)] -= lower[e];
+          _supply[_graph.target(e)] += lower[e];
+        }
       }
       _valid_supply = true;
Index: lemon/cycle_canceling.h
===================================================================
--- lemon/cycle_canceling.h	(revision 2623)
+++ lemon/cycle_canceling.h	(revision 2629)
@@ -168,21 +168,22 @@
                     const CostMap &cost,
                     const SupplyMap &supply ) :
-      _graph(graph), _lower(&lower), _capacity(graph), _cost(cost),
-      _supply(graph), _flow(NULL), _local_flow(false),
+      _graph(graph), _lower(&lower), _capacity(capacity), _cost(cost),
+      _supply(supply), _flow(NULL), _local_flow(false),
       _potential(NULL), _local_potential(false), _res_graph(NULL),
       _res_cost(_cost)
     {
-      // Removing non-zero lower bounds
-      _capacity = subMap(capacity, lower);
+      // Check the sum of supply values
       Supply sum = 0;
-      for (NodeIt n(_graph); n != INVALID; ++n) {
-        Supply s = supply[n];
-        for (InEdgeIt e(_graph, n); e != INVALID; ++e)
-          s += lower[e];
-        for (OutEdgeIt e(_graph, n); e != INVALID; ++e)
-          s -= lower[e];
-        sum += (_supply[n] = s);
-      }
+      for (NodeIt n(_graph); n != INVALID; ++n) sum += _supply[n];
       _valid_supply = sum == 0;
+
+      // Remove non-zero lower bounds
+      for (EdgeIt e(_graph); e != INVALID; ++e) {
+        if (lower[e] != 0) {
+          _capacity[e] -= lower[e];
+          _supply[_graph.source(e)] -= lower[e];
+          _supply[_graph.target(e)] += lower[e];
+        }
+      }
     }
 
@@ -204,5 +205,5 @@
       _res_cost(_cost)
     {
-      // Checking the sum of supply values
+      // Check the sum of supply values
       Supply sum = 0;
       for (NodeIt n(_graph); n != INVALID; ++n) sum += _supply[n];
@@ -228,20 +229,18 @@
                     Node s, Node t,
                     Supply flow_value ) :
-      _graph(graph), _lower(&lower), _capacity(graph), _cost(cost),
-      _supply(graph), _flow(NULL), _local_flow(false),
+      _graph(graph), _lower(&lower), _capacity(capacity), _cost(cost),
+      _supply(graph, 0), _flow(NULL), _local_flow(false),
       _potential(NULL), _local_potential(false), _res_graph(NULL),
       _res_cost(_cost)
     {
-      // Removing non-zero lower bounds
-      _capacity = subMap(capacity, lower);
-      for (NodeIt n(_graph); n != INVALID; ++n) {
-        Supply sum = 0;
-        if (n == s) sum =  flow_value;
-        if (n == t) sum = -flow_value;
-        for (InEdgeIt e(_graph, n); e != INVALID; ++e)
-          sum += lower[e];
-        for (OutEdgeIt e(_graph, n); e != INVALID; ++e)
-          sum -= lower[e];
-        _supply[n] = sum;
+      // Remove non-zero lower bounds
+      _supply[s] =  flow_value;
+      _supply[t] = -flow_value;
+      for (EdgeIt e(_graph); e != INVALID; ++e) {
+        if (lower[e] != 0) {
+          _capacity[e] -= lower[e];
+          _supply[_graph.source(e)] -= lower[e];
+          _supply[_graph.target(e)] += lower[e];
+        }
       }
       _valid_supply = true;
Index: lemon/network_simplex.h
===================================================================
--- lemon/network_simplex.h	(revision 2628)
+++ lemon/network_simplex.h	(revision 2629)
@@ -612,5 +612,5 @@
       _node_ref(graph), _edge_ref(graph)
     {
-      // Checking the sum of supply values
+      // Check the sum of supply values
       Supply sum = 0;
       for (typename Graph::NodeIt n(_graph_ref); n != INVALID; ++n)
@@ -618,24 +618,22 @@
       if (!(_valid_supply = sum == 0)) return;
 
-      // Copying _graph_ref to _graph
+      // Copy _graph_ref to _graph
       _graph.reserveNode(countNodes(_graph_ref) + 1);
       _graph.reserveEdge(countEdges(_graph_ref) + countNodes(_graph_ref));
       copyGraph(_graph, _graph_ref)
+        .edgeMap(_capacity, capacity)
         .edgeMap(_cost, cost)
+        .nodeMap(_supply, supply)
         .nodeRef(_node_ref)
         .edgeRef(_edge_ref)
         .run();
 
-      // Removing non-zero lower bounds
+      // Remove non-zero lower bounds
       for (typename Graph::EdgeIt e(_graph_ref); e != INVALID; ++e) {
+        if (lower[e] != 0) {
         _capacity[_edge_ref[e]] = capacity[e] - lower[e];
-      }
-      for (typename Graph::NodeIt n(_graph_ref); n != INVALID; ++n) {
-        Supply s = supply[n];
-        for (typename Graph::InEdgeIt e(_graph_ref, n); e != INVALID; ++e)
-          s += lower[e];
-        for (typename Graph::OutEdgeIt e(_graph_ref, n); e != INVALID; ++e)
-          s -= lower[e];
-        _supply[_node_ref[n]] = s;
+          _supply[_node_ref[_graph_ref.source(e)]] -= lower[e];
+          _supply[_node_ref[_graph_ref.target(e)]] += lower[e];
+      }
       }
     }
@@ -662,5 +660,5 @@
       _node_ref(graph), _edge_ref(graph)
     {
-      // Checking the sum of supply values
+      // Check the sum of supply values
       Supply sum = 0;
       for (typename Graph::NodeIt n(_graph_ref); n != INVALID; ++n)
@@ -668,5 +666,7 @@
       if (!(_valid_supply = sum == 0)) return;
 
-      // Copying _graph_ref to graph
+      // Copy _graph_ref to _graph
+      _graph.reserveNode(countNodes(_graph_ref) + 1);
+      _graph.reserveEdge(countEdges(_graph_ref) + countNodes(_graph_ref));
       copyGraph(_graph, _graph_ref)
         .edgeMap(_capacity, capacity)
@@ -698,5 +698,5 @@
                     typename SupplyMap::Value flow_value ) :
       _graph(), _graph_ref(graph), _lower(&lower), _capacity(_graph),
-      _cost(_graph), _supply(_graph), _flow(_graph),
+      _cost(_graph), _supply(_graph, 0), _flow(_graph),
       _potential(_graph), _depth(_graph), _parent(_graph),
       _pred_edge(_graph), _thread(_graph), _forward(_graph),
@@ -706,6 +706,9 @@
       _node_ref(graph), _edge_ref(graph)
     {
-      // Copying _graph_ref to graph
+      // Copy _graph_ref to graph
+      _graph.reserveNode(countNodes(_graph_ref) + 1);
+      _graph.reserveEdge(countEdges(_graph_ref) + countNodes(_graph_ref));
       copyGraph(_graph, _graph_ref)
+        .edgeMap(_capacity, capacity)
         .edgeMap(_cost, cost)
         .nodeRef(_node_ref)
@@ -713,17 +716,13 @@
         .run();
 
-      // Removing non-zero lower bounds
+      // Remove non-zero lower bounds
+      _supply[_node_ref[s]] =  flow_value;
+      _supply[_node_ref[t]] = -flow_value;
       for (typename Graph::EdgeIt e(_graph_ref); e != INVALID; ++e) {
+        if (lower[e] != 0) {
         _capacity[_edge_ref[e]] = capacity[e] - lower[e];
-      }
-      for (typename Graph::NodeIt n(_graph_ref); n != INVALID; ++n) {
-        Supply sum = 0;
-        if (n == s) sum =  flow_value;
-        if (n == t) sum = -flow_value;
-        for (typename Graph::InEdgeIt e(_graph_ref, n); e != INVALID; ++e)
-          sum += lower[e];
-        for (typename Graph::OutEdgeIt e(_graph_ref, n); e != INVALID; ++e)
-          sum -= lower[e];
-        _supply[_node_ref[n]] = sum;
+          _supply[_node_ref[_graph_ref.source(e)]] -= lower[e];
+          _supply[_node_ref[_graph_ref.target(e)]] += lower[e];
+      }
       }
       _valid_supply = true;
@@ -756,5 +755,7 @@
       _node_ref(graph), _edge_ref(graph)
     {
-      // Copying _graph_ref to graph
+      // Copy _graph_ref to graph
+      _graph.reserveNode(countNodes(_graph_ref) + 1);
+      _graph.reserveEdge(countEdges(_graph_ref) + countNodes(_graph_ref));
       copyGraph(_graph, _graph_ref)
         .edgeMap(_capacity, capacity)
