#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:1000000000")
FILE* stream;
const int INF = (int)1e9 + 7;
const long long INFL = (long long)1e18;
const int SIZE = int(2e7 + 10);
const int TSIZE = int(1e3 + 10);
const long double eps = 0.00000001;
const int MOD = int(1e9) + 7;
long long POW(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  a %= mod;
  long long cur = POW(a % mod, b / 2, mod) % mod;
  if (b % 2 == 0)
    return cur * cur % mod;
  else
    return cur * cur % mod * a % mod;
}
vector<int> col, us;
vector<vector<int> > sons;
void dfs(int cur) {
  for (int i = 0; i < sons[cur].size(); i++) {
    if (!us[sons[cur][i]]) {
      col[sons[cur][i]] *= -1;
      printf("%d ", sons[cur][i]);
      us[sons[cur][i]] = 1;
      dfs(sons[cur][i]);
      col[cur] *= -1;
      if (cur == 1 && i + 1 == sons[cur].size() && col[cur] == -1 &&
          col[sons[cur][i]] == 1)
        return;
      printf("%d ", cur);
      if (col[sons[cur][i]] == -1) {
        col[sons[cur][i]] *= -1;
        printf("%d ", sons[cur][i]);
        us[sons[cur][i]] = 1;
        dfs(sons[cur][i]);
        col[cur] *= -1;
        if (cur == 1 && i + 1 == sons[cur].size() && col[cur] == -1 &&
            col[sons[cur][i]] == 1)
          return;
        printf("%d ", cur);
      }
    }
  }
}
void accept() {
  int n;
  cin >> n;
  col.resize(n + 1);
  for (int i = 0; i < n; i++) {
    scanf("%d", &col[i + 1]);
  }
  sons.resize(n + 1);
  us.resize(n + 1);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    sons[x].push_back(y);
    sons[y].push_back(x);
  }
  cout << "1 ";
  us[1] = 1;
  dfs(1);
}
void solution() {
  accept();
  return;
}
int main() {
  srand(time(0));
  solution();
  return 0;
}
