1. 
package contestVolumes.volume108;

import java.util.*;

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 10842 - Traffic Flow
* Link: http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&category=20&page=show_problem&problem=1783
*
* @author Siegfried Ippisch
* @version 1.0
*
* Method : Prim's algorithm
* Status : Accepted
* Runtime: 2.048
*/
public class TrafficFlow {

public static void main(String[] args){
Scanner in = new Scanner(System.in);
int cases = in.nextInt();

for(int c=1; c<=cases; c++){
int n = in.nextInt();
int m = in.nextInt();

int[][] adja = new int[n][n];
for(int i=0; i<m; i++){
int u = in.nextInt();
int v = in.nextInt();
int costs = Math.max(in.nextInt(),adja[u][v]);
adja[u][v] = costs;
adja[v][u] = costs;
}

if(n==1){
System.out.println("Case #"+c+": "+adja[0][0]);
continue;
}

int min = Integer.MAX_VALUE;

List<Integer> tree = new LinkedList<Integer>();
tree.add(0);

List<Integer> nodes = new LinkedList<Integer>();
for(int i=1; i<n; i++)
nodes.add(i);

while(!nodes.isEmpty()){
int edgeCosts = 0; // kosten der kante
int newNode = -1; // Node, das zum Baum hinzugefügt wird, wenn die Kosten maximal sind
for(int i: tree)
for(int j: nodes)
if(adja[i][j] > edgeCosts){
edgeCosts = adja[i][j];
newNode = j;
}

tree.add(nodes.remove(nodes.indexOf(newNode)));
min = Math.min(min, edgeCosts);
}

System.out.println("Case #"+c+": "+min);
}

in.close();
}

}

2.

package acm_10842_traffic_flow;

import java.util.PriorityQueue;
import java.util.Scanner;

/**
* FWP, Ausgew¦hlte Probleme aus dem ACM Programming Contest, SS10
* Problem: acm_10842_traffic_flow
* Link: http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&category=20&page=show_problem&problem=1783
*
* @author Martin Lambeck
* @version 1.0, 14.08.2010
*
* Method : maximum spanning tree
* Status : Accepted
* Runtime: 2.056
*/


public class Main
{
static Scanner sc = new Scanner(System.in);
static int tcase = 0;

public static void main(String... args)
{
int cases = sc.nextInt();

for (int i = 0; i < cases; i++)
testcase();
}

public static void testcase()
{
int v = sc.nextInt();
int e = sc.nextInt();
int[][] adja;
int v1, v2, fl;


adja = new int[v][v];

for (int i = 0; i < e; i++)
{
v1 = sc.nextInt();
v2 = sc.nextInt();
fl = sc.nextInt();

if (fl > adja[v1][v2])
{
adja[v1][v2] = fl;
adja[v2][v1] = fl;
}
}

tcase++;
System.out.print("Case #" + tcase + ": ");
System.out.println(mst(adja));


}

static int mst(int[][] adja)
{
boolean visited[] = new boolean[adja.length];
PriorityQueue<Edge> pq = new PriorityQueue<Edge>(1000);
Edge e;
int minflow = Integer.MAX_VALUE;

for (int i = 1; i < adja.length; i++)
{
if (adja[0][i] > 0)
pq.add(new Edge(i, adja[0][i]));
}

visited[0] = true;

while (pq.size() > 0)
{
e = pq.poll();

if (visited[e.to])
continue;

visited[e.to] = true;

if (e.flow < minflow)
minflow = e.flow;

for (int i = 0; i < adja.length; i++)
{
if ((adja[e.to][i] > 0) && !visited[i])
{
pq.add(new Edge(i, adja[e.to][i]));
}
}
}


return minflow;
}
}

class Edge implements Comparable<Edge>
{
int to;
int flow;

public Edge(int t, int f)
{
to = t;
flow = f;
}

public int compareTo(Edge o)
{
if (flow == o.flow)
return 0;

return (flow < o.flow ? 1 : -1);
}
}