#include <bits/stdc++.h>
using namespace std;
const int N = 500023;
bool vis[N];
vector<int> adj[N];
int indx = 0;
vector<long long int> order;
int par[N];
void euler(int curr) {
  vis[curr] = 1;
  order.push_back(curr);
  for (int i : adj[curr]) {
    if (!vis[i]) {
      euler(i);
      order.push_back(curr);
    }
  }
}
void bfs(int root) {
  queue<int> q;
  vis[root] = 1;
  q.push(root);
  par[root] = 0;
  while (!q.empty()) {
    int curr = q.front();
    q.pop();
    for (int i : adj[curr]) {
      if (vis[i]) continue;
      vis[i] = 1;
      par[i] = curr;
      q.push(i);
    }
  }
}
void solve() {
  long long int n;
  cin >> n;
  long long int color[n + 1];
  for (long long int i = 0; i < n; i++) {
    long long int c;
    cin >> c;
    color[i + 1] = c;
  }
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  euler(1);
  for (long long int i = 0; i < n + 1; i++) vis[i] = 0;
  bfs(1);
  vector<long long int> ans;
  ans.push_back(order[0]);
  for (int i = 1; i < order.size() - 1; i++) {
    if (order[i + 1] == par[order[i]]) {
      ans.push_back(order[i]);
      color[order[i]] *= -1;
      if (color[order[i]] == -1) {
        color[order[i + 1]] *= -1;
        color[order[i]] *= -1;
        ans.push_back(order[i + 1]);
        ans.push_back(order[i]);
      }
    } else {
      ans.push_back(order[i]);
      color[order[i]] *= -1;
    }
  }
  for (int i : ans) cout << i << ' ';
  if (color[1] == -1) cout << 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  int t = 0;
  while (t++ < T) {
    solve();
  }
}
