Problem: I see a pink boar and I want it painted black. Black boars look much more awesome and mighty than the pink ones. Since Jaggy became the ruler of the forest, he has been trying his best to improve the diplomatic relations between the forest region and the nearby ones. 

Some other rulers, however, have requested too much in return for peace between their two regions, so he realized he has to resort to intimidation. Once a delegate for diplomatic relations of a neighboring region visits Jaggy’s forest, if they see a whole bunch of black boars, they might suddenly change their mind about attacking Jaggy. Black boars are really scary, after all. 

Jaggy’s forest can be represented as a tree (connected graph without cycles) with n vertices. Each vertex represents a boar and is colored either black or pink. Jaggy has sent a squirrel to travel through the forest and paint all the boars black. The squirrel, however, is quite unusually trained and while it traverses the graph, it changes the color of every vertex it visits, regardless of its initial color: pink vertices become black and black vertices become pink. 

Since Jaggy is too busy to plan the squirrel’s route, he needs your help. He wants you to construct a walk through the tree starting from vertex 1 such that in the end all vertices are black. A walk is a sequence of vertices, such that every consecutive pair has an edge between them in a tree.

Input

The first line of input contains integer n (2 ≤ n ≤ 200 000), denoting the number of vertices in the tree. The following n lines contains n integers, which represent the color of the nodes.

If the i-th integer is 1, if the i-th vertex is black and  - 1 if the i-th vertex is pink.

Each of the next n - 1 lines contains two integers, which represent the indexes of the vertices which are connected by the edge. Vertices are numbered starting with 1.

Output

Output path of a squirrel: output a sequence of visited nodes' indexes in order of visiting. In case of all the nodes are initially black, you should print 1. Solution is guaranteed to exist. If there are multiple solutions to the problem you can output any of them provided length of sequence is not longer than 107.

Example

Input

5
1
1
-1
1
-1
2 5
4 3
2 4
4 1


Output

1 4 2 5 2 4 3 4 1 4 1

Note

At the beginning squirrel is at node 1 and its color is black. Next steps are as follows: 

  * From node 1 we walk to node 4 and change its color to pink. 
  * From node 4 we walk to node 2 and change its color to pink. 
  * From node 2 we walk to node 5 and change its color to black. 
  * From node 5 we return to node 2 and change its color to black. 
  * From node 2 we walk to node 4 and change its color to black. 
  * We visit node 3 and change its color to black. 
  * We visit node 4 and change its color to pink. 
  * We visit node 1 and change its color to pink. 
  * We visit node 4 and change its color to black. 
  * We visit node 1 and change its color to black. 

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Stack;
import java.util.StringTokenizer;

public class E {

	static int N;
	static ArrayList<Integer>[] adjList;
	static int[] L, P, outT;
	static int c;
	 
	static void dfs(int u, int p, int l) {
		P[u] = p;
		L[u] = l;
		
		for(int v: adjList[u]) {
			if(v != p) {
				dfs(v, u, l + 1);
			}
		}
		
		outT[u] = c++;
	}


	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		N = sc.nextInt();
		
		ArrayList<Integer> red = new ArrayList<>();
		boolean rootR = sc.nextInt() == -1;
		boolean[] bla = new boolean[N];
		boolean[] blabla = new boolean[N];
		for (int i = 1; i < N; i++) 
			if(sc.nextInt() == -1)
				red.add(i);
		
		adjList = new ArrayList[N];
		for (int i = 0; i < N; i++) 
			adjList[i] = new ArrayList<>();
		
		for (int i = 0; i < N - 1; i++) {
			int f = sc.nextInt() - 1;
			int t = sc.nextInt() - 1;
			
			adjList[f].add(t);
			adjList[t].add(f);
		}
		
		P = new int[N];
		L = new int[N];
		outT = new int[N];
		c = 1;
		dfs(0, -1, 0);
		PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				return outT[o1] - outT[o2];
			}
		});
		
		for(int x : red) {
			pq.add(x);
			bla[x] = true;
			blabla[x] = true;
		}
		
		
		if(red.size() == 0) {
			pq.add(1);
			pq.add(1);
			bla[1] = true;
			blabla[1] = true;
		}
		Stack<Integer> stack = new Stack<>();
		int cur = pq.remove();
		int l = cur;
		while(cur != -1) {
			stack.add(cur);
			cur = P[cur];
		}
		
		while(!stack.isEmpty())
			out.print(stack.pop() + 1 +" ");
		
		while (!pq.isEmpty()) {
			Stack<Integer> s1 = new Stack<>();
			Stack<Integer> s2 = new Stack<>();
			int x = pq.remove();
			if(!blabla[x]) {
				blabla[x] = true;
				pq.add(x);
			}
			s1.add(l);
			s2.add(x);
			
			while(P[s1.peek()] != P[s2.peek()])
				if(L[s1.peek()] > L[s2.peek()])
					s1.push(P[s1.peek()]);
				else {
					s2.push(P[s2.peek()]);
				}
			
			if(P[s2.peek()] == 0)
				rootR = !rootR;
			else {
				if(!bla[P[s2.peek()]]) {
					bla[P[s2.peek()]] = true;
					pq.add(P[s2.peek()]);
				}
				blabla[P[s2.peek()]] = ! blabla[P[s2.peek()]];
			}
			s2.push(P[s2.peek()]);
			
			while(s1.size() > 1)
				s2.add(s1.pop());
			
			while(!s2.isEmpty())
				out.print(s2.pop() + 1 + " ");
			l = x;
		}
		
		cur = l;
		while(P[cur] != 0) {
			out.print(P[cur] + 1 + " ");
			cur = P[cur];
		}
		
		if(rootR)
			out.println(1);
		else
			out.println();
		
		
		out.flush();
		out.close();
	}


	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public Scanner(String file) throws FileNotFoundException{	br = new BufferedReader(new FileReader(file));}


		public String next() throws IOException {
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

	}

}