#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> tour;
vector<int> adj[maxn];
int a[maxn];
inline void f(int v) { a[v] *= -1, tour.push_back(v); }
void dfs(int v, int p) {
  if (v) a[v] *= -1;
  tour.push_back(v);
  for (int u : adj[v])
    if (u != p) {
      dfs(u, v);
      f(v);
    }
  if (v && a[v] == -1) f(p), f(v);
}
int main() {
  int n;
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(0, 0);
  if (a[0] == -1) {
    int u = adj[0][0];
    f(u), f(0), f(u);
  }
  for (int i : tour) cout << i + 1 << " ";
  cout << endl;
}
