#include <bits/stdc++.h>
using namespace std;
inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; }
inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; }
int n, u, v;
int a[200100], f[200100];
vector<int> g[200100];
vector<int> ans;
void dfs(int t, int fa) {
  for (auto v : g[t])
    if (v != fa) {
      dfs(v, t);
      if (a[v] == 1)
        f[v] = 2;
      else
        f[v] = 1, a[t] = -a[t];
    }
}
void DFS(int t, int fa) {
  for (auto v : g[t])
    if (v != fa) {
      if (f[v] == 2) ans.push_back(v), ans.push_back(t);
      ans.push_back(v);
      DFS(v, t);
      ans.push_back(t);
    }
}
int main() {
  scanf("%d", &n);
  bool flag = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    if (a[i] == -1) flag = 1;
  }
  if (!flag) {
    printf("1");
    return 0;
  }
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  ans.push_back(1);
  DFS(1, 0);
  if (a[1] == -1) ans.pop_back();
  for (auto v : ans) printf("%d ", v);
  return 0;
}
