#include <bits/stdc++.h>
using namespace std;
int n, m, tem[200005], cor[200005];
vector<int> adj[200005];
vector<int> ans;
void pre(int x, int pai) {
  if (cor[x] == 0) tem[x] = 1;
  for (int i = 0; i < ((int)(adj[x]).size()); i++) {
    int y = adj[x][i];
    if (y == pai) continue;
    pre(y, x);
    if (tem[y]) tem[x] = 1;
  }
}
void dfs(int x, int pai) {
  for (int i = 0; i < ((int)(adj[x]).size()); i++) {
    int y = adj[x][i];
    if (y == pai || !tem[y]) continue;
    ans.push_back(y);
    cor[y] ^= 1;
    dfs(y, x);
  }
  if (x == pai) return;
  ans.push_back(pai);
  cor[pai] ^= 1;
  if (cor[x] == 0) ans.push_back(x), ans.push_back(pai), cor[pai] ^= 1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cor[i];
    if (cor[i] == -1) cor[i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  ans.push_back(0);
  pre(0, 0);
  dfs(0, 0);
  if (cor[0] == 0)
    ans.push_back(adj[0][0]), ans.push_back(0), ans.push_back(adj[0][0]);
  for (int i = 0; i < ((int)(ans).size()); i++) cout << ans[i] + 1 << " ";
  cout << endl;
}
