#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5), mod = int(1e9) + 7;
int dp[N], cnt[N], first[N];
vector<int> res, a[N];
int n, x, y;
void dfsf(int v, int p = -1) {
  cnt[v] = (first[v] == 0);
  dp[v] = 1;
  for (int i = 0; i < a[v].size(); i++) {
    int to = a[v][i];
    if (to == p) continue;
    dfsf(to, v);
    dp[v] += dp[to];
    cnt[v] += cnt[to];
  }
}
void dfsn(int v, int p = -1) {
  res.push_back(v);
  for (int i = 0; i < a[v].size(); i++) {
    int to = a[v][i];
    if (to == p) continue;
    if (cnt[to] != 0) {
      first[to] = 1 - first[to];
      dfsn(to, v);
      res.push_back(v);
      first[v] = 1 - first[v];
      if (first[to] == 0) {
        res.push_back(to);
        res.push_back(v);
        first[v] = 1 - first[v];
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &first[i]);
    if (first[i] == -1) first[i] = 0;
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  dfsf(1);
  dfsn(1);
  if (first[1] == 0) {
    int to = a[1][0];
    res.push_back(to);
    res.push_back(1);
    res.push_back(to);
  }
  for (int i = 0; i < res.size(); i++) printf("%d ", res[i]);
  return 0;
}
