#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200005;
long long a[maxn];
vector<long long> adj[maxn];
vector<long long> res;
void dfs(long long u, long long p) {
  res.push_back(u);
  for (long long v : adj[u]) {
    if (v == p) continue;
    if (a[v] == -1)
      a[v] = 1;
    else
      a[v] = -1;
    dfs(v, u);
    res.push_back(u);
    if (a[u] == -1)
      a[u] = 1;
    else
      a[u] = -1;
  }
  for (long long v : adj[u]) {
    if (a[v] == -1) {
      res.push_back(v);
      res.push_back(u);
      a[v] = 1;
      if (a[u] == -1)
        a[u] = 1;
      else
        a[u] = -1;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 1);
  if (a[1] == -1) {
    res.push_back(adj[1][0]);
    res.push_back(1);
    res.push_back(adj[1][0]);
  }
  for (long long i : res) cout << i << ' ';
  cout << '\n';
}
