private static void updateTreeAndLowerAndUpperEdges(
			NetworkEdge enteringEdge, NetworkEdge leavingEdge, LinkedList<NetworkVertex> subtreeT2) {
		
		// remove entering edge from L or U
		if (lEdges.containsKey(enteringEdge.getKey())) {
			lEdges.remove(enteringEdge.getKey());
		} else {
			uEdges.remove(enteringEdge.getKey());
		}
		
		// add leaving edge to L or U
		if (leavingEdge.getFlow() == leavingEdge.getLowerBound()) {
			lEdges.put(leavingEdge.getKey(), leavingEdge);
		} else {
			uEdges.put(leavingEdge.getKey(), leavingEdge);
		}

		if (leavingEdge == enteringEdge) {
			// no need to change T
			return;
		}

		int v = ((NetworkVertex) enteringEdge.getHead()).getId();
		// Let v be the node located in the subtree T2
		if (!subtreeT2.contains(enteringEdge.getHead())) {
			v = ((NetworkVertex) enteringEdge.getTail()).getId();
		}
		int z = ((NetworkVertex) leavingEdge.getTail()).getId();
		int y = ((NetworkVertex) leavingEdge.getHead()).getId();
		if (d[z] > d[y]) {
			// Make sure that y is the node located deeper than z in the tree
			y = z;
		}
		
		// remove leaving edge from T
		// by updating the array tree
		int w = v;
		NetworkEdge e = tree[w];
		while (w != y) {
			int parent = p[w];
			NetworkEdge edgeToParent = tree[parent];
			tree[parent] = e;
			e = edgeToParent;
			w = parent;
		}
		// add entering edge to T
		tree[v] = enteringEdge;
		
//		for (NetworkEdge edge : tree) {
//			System.out.println(edge);
//		}
		
	}