import java.util.ArrayList; import java.util.List; import java.util.Queue; import java.util.Scanner; import java.util.Stack; public class Greedy_Pizza { static double[] enjoyment; static List> connections; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); enjoyment = new double[n]; connections = new ArrayList>(n); for(int i = 0; i < n; i++) connections.add(new ArrayList()); for(int i = 0; i < n; i++) enjoyment[i] = sc.nextDouble(); for(int j = 0; j < m; j++) { int s = sc.nextInt(); int t = sc.nextInt(); connections.get(s).add(t); } System.out.println(greedy(0)); } static double greedy(int s) { int best_path = -1; double best_value = enjoyment[s]; int option = 0; for(int c: connections.get(s)) { // Two options: eat both, skip first. double val1 = enjoyment[s] + 0.5 * enjoyment[c]; double val2 = enjoyment[c]; double max = Math.max(val1, val2); if(max >= best_value) { best_value = max; best_path = c; if(max == val1) option = 1; if(max == val2) option = 2; } } if(connections.get(s).isEmpty()) return enjoyment[s]; if(option == 0) return enjoyment[s] + 0.5 * greedy(connections.get(s).get(0)); // We've found nothing appetizing in the next step. if(option == 1) return enjoyment[s] + 0.5 * greedy(best_path); if(option == 2) return greedy(best_path); return 0; } }