#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
set<int> g[MAXN];
vector<int> ans;
int n;
int col[MAXN];
void work(int u);
void dfs(int u, int p) {
  col[u] ^= 1;
  ans.push_back(u);
  if (g[u].size() == 1 && *g[u].begin() == p) {
    work(u);
  } else {
    for (auto v : g[u]) {
      if (v != p) {
        dfs(v, u);
        break;
      }
    }
  }
}
void work(int u) {
  int p = *g[u].begin();
  if (!col[u]) {
    ans.push_back(p);
    col[p] ^= 1;
    ans.push_back(u);
    col[u] ^= 1;
  }
  if (col[p] == 1 && g[p].size() == 1) return;
  g[u].erase(p);
  g[p].erase(u);
  if (g[p].empty())
    dfs(p, 0);
  else
    dfs(p, *g[p].begin());
}
int main(int argc, char* argv[]) {
  cin >> n;
  bool flag = 1;
  for (int i = 1; i <= n; i++) {
    cin >> col[i];
    if (col[i] == -1) col[i] = 0;
    flag &= col[i];
  }
  int x, y;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    g[x].insert(y);
    g[y].insert(x);
  }
  if (flag) {
    cout << "1";
    return 0;
  }
  ans.push_back(1);
  dfs(*g[1].begin(), 1);
  for (auto v : ans) cout << v << " ";
  return 0;
}
