public State bellmanFord(Node f, Node t) {
		TreeMap<Node, Double> cost = new TreeMap<Node, Double>();
		TreeMap<Node, Node> bt = new TreeMap<Node, Node>();
		for (Node n: nodes) { cost.put(n, Double.MAX_VALUE); bt.put(n, null); }
		cost.put(f, 0.0);
		boolean update = true;
		while (update) {
			update = false;
			for (Node a: nodes) for (Node b: edges.get(a).keySet()) {
				double buf = cost.get(a) + edge(a, b);
				if (cost.get(b) > buf) { cost.put(b, buf); bt.put(b, a); update = true; }
			}
		}
		LinkedList<Node> path = new LinkedList<Node>(); Node cur = t;
		while (cur != null) { path.addFirst(cur); if (cur.compareTo(f) == 0) break; else cur = bt.get(cur); }
		return cur == null ? null : new State(path.toArray(new Node[path.size()]));
	}