#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
inline void RI(int &x) {
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0';
}
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double dnf = 1e18;
const double eps = 1e-12;
const long long mod = 10007;
const int maxn = 200010;
vector<int> side[maxn], route;
int c[maxn];
int n;
void dfs(int u, int pre) {
  for (int i = 0; i < side[u].size(); i++) {
    int v = side[u][i];
    if (v == pre) continue;
    route.push_back(v);
    c[v] = -c[v];
    dfs(v, u);
    if (c[v] == -1) {
      route.push_back(u);
      c[u] = -c[u];
      route.push_back(v);
    }
    route.push_back(u);
    c[u] = -c[u];
  }
}
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) scanf("%d", &c[i]), side[i].clear();
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      RI(u);
      RI(v);
      side[u].push_back(v);
      side[v].push_back(u);
    }
    route.clear();
    route.push_back(1);
    dfs(1, -1);
    if (c[1] == -1) {
      int u = side[1][0];
      route.push_back(u);
      route.push_back(1);
      route.push_back(u);
    }
    for (int i = 0; i < route.size() - 1; i++) printf("%d ", route[i]);
    cout << *route.rbegin() << endl;
  }
}
