#include <bits/stdc++.h>
using namespace std;
vector<int> vc[200000], path;
int cou[200000], node[200000], ara[200000], n, cnt = 0;
void dfs(int v, int par) {
  cou[v] = ara[v];
  node[v] = 1;
  for (int i = 0; i < vc[v].size(); i++) {
    int w = vc[v][i];
    if (w == par) continue;
    dfs(w, v);
    cou[v] += cou[w];
    node[v] += node[w];
  }
}
void print(int v, int par) {
  if (par != -1) {
    ara[v]++;
    ara[v] = ara[v] % 2;
    if (ara[v] == 1)
      cnt++;
    else
      cnt--;
  }
  for (int i = 0; i < vc[v].size(); i++) {
    if (cnt == n) return;
    int w = vc[v][i];
    if (w == par) continue;
    path.push_back(v);
    path.push_back(w);
    print(w, v);
    if (ara[w] == 1 && ara[v] == 1 && cnt == n) return;
    ara[v]++;
    ara[v] = ara[v] % 2;
    if (ara[v] == 1)
      cnt++;
    else
      cnt--;
    path.push_back(w);
    path.push_back(v);
    if (ara[w] == 0) {
      ara[w] = 1;
      cnt++;
      path.push_back(v);
      path.push_back(w);
      if (cnt == n) return;
      path.push_back(w);
      path.push_back(v);
      ara[v] = (ara[v] + 1) % 2;
      if (ara[v] == 0)
        cnt--;
      else
        cnt++;
    }
    if (cnt == n) return;
  }
  if (par == -1 && ara[v] == 0) {
    for (int i = 0; i < vc[v].size(); i++) {
      int w = vc[v][i];
      path.push_back(v);
      path.push_back(w);
      path.push_back(w);
      path.push_back(v);
      path.push_back(v);
      path.push_back(w);
      ara[v] = 1;
      cnt++;
    }
  }
}
int main() {
  int i, j, k, l, m;
  cin >> n;
  cnt = 0;
  for (i = 1; i <= n; i++) {
    cin >> m;
    if (m == -1)
      ara[i] = 0;
    else
      ara[i] = 1;
    if (ara[i] == 1) cnt++;
  }
  for (i = 1; i < n; i++) {
    cin >> l >> k;
    vc[k].push_back(l);
    vc[l].push_back(k);
  }
  if (cnt == n) {
    printf("1\n");
    return 0;
  }
  dfs(1, -1);
  print(1, -1);
  for (i = 0; i < path.size(); i++) {
    if (i > 0 && path[i] == path[i - 1]) continue;
    cout << path[i] << " ";
  }
}
