#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
long long n, c, u, v, cnt, parent[MAXN];
vector<int> node[MAXN];
vector<int> path;
bool color[MAXN], mark[MAXN];
void dfs(int v) {
  mark[v] = true;
  for (int i = 0; i < node[v].size(); i++) {
    if (!mark[node[v][i]]) {
      path.push_back(node[v][i]);
      parent[node[v][i]] = v;
      color[node[v][i]] = !color[node[v][i]];
      dfs(node[v][i]);
      path.push_back(v);
      color[v] = !color[v];
    }
  }
  if (color[v]) {
    path.push_back(parent[v]);
    path.push_back(v);
    color[parent[v]] = !color[parent[v]];
    color[v] = !color[v];
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c;
    if (c == 1) {
      color[i] = 0;
      cnt++;
    } else
      color[i] = 1;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    node[v].push_back(u);
    node[u].push_back(v);
  }
  if (cnt == n)
    cout << 1 << '\n';
  else {
    mark[1] = true;
    color[1] = !color[1];
    for (int i = 0; i < node[1].size(); i++) {
      path.push_back(1);
      path.push_back(node[1][i]);
      color[node[1][i]] = !color[node[1][i]];
      parent[node[1][i]] = 1;
      dfs(node[1][i]);
      color[1] = !color[1];
    }
    if (color[1]) path.push_back(1);
    for (int i = 0; i < path.size(); i++) {
      cout << path[i] << ' ';
    }
  }
  return 0;
}
