#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
vector<int> adj[MAXN];
bool mark[MAXN], f[MAXN];
int n, la, lb, ans;
void dfs(int v, int z) {
  mark[v] = true;
  f[v] = !f[v];
  cout << v << ' ';
  for (auto i : adj[v]) {
    if (!mark[i]) {
      dfs(i, v);
      f[v] = !f[v];
      cout << v << ' ';
    }
  }
  if (!f[v]) {
    cout << z << ' ' << v << ' ';
    f[z] = !f[z];
    f[v] = true;
  }
  return;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> la;
    if (la == 1) {
      f[i] = true;
      ans++;
    }
  }
  for (int i = 1; i < n; i++) {
    cin >> la >> lb;
    adj[la].push_back(lb);
    adj[lb].push_back(la);
  }
  if (ans == n) return cout << 1 << endl, 0;
  for (auto i : adj[1]) {
    cout << 1 << ' ';
    dfs(i, 1);
    f[1] = !f[1];
  }
  if (f[1]) cout << 1 << endl;
  cin >> n;
  return 0;
}
