#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 5;
int color[mx], par[mx];
vector<int> ans;
int black;
vector<int> g[mx];
vector<int> path;
void dfs(int u, int p = -1) {
  path.push_back(u);
  par[u] = p;
  for (int v : g[u])
    if (v ^ p) dfs(v, u);
  if (p != -1) path.push_back(p);
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> color[i];
    if (color[i] == -1) color[i] = 0;
  }
  black = accumulate(color + 1, color + n + 1, 0);
  if (black == n) {
    cout << 1;
    exit(0);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  ans.push_back(1);
  for (int i = 1; i < path.size(); i++) {
    int u = path[i];
    color[u] ^= 1;
    ans.push_back(u);
    if (u == 1 || color[u]) continue;
    int p = par[u];
    color[u] ^= 1;
    color[p] ^= 1;
    ans.push_back(p);
    ans.push_back(u);
  }
  if (color[1] == 0) {
    int u = 1;
    int v = g[1][0];
    ans.push_back(v);
    ans.push_back(u);
    ans.push_back(v);
    color[v] ^= 1;
    color[u] ^= 1;
    color[v] ^= 1;
  }
  for (int x : ans) cout << x << " ";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int testcase = 1;
  for (int i = 1; i <= testcase; i++) {
    solve();
  }
  return 0;
}
