#include <bits/stdc++.h>
using namespace std;
vector<std::list<int> > tree;
vector<int> color;
vector<int> visited;
vector<int> path;
void solve(int v) {
  visited[v] = 1;
  for (std::list<int>::const_iterator itr = tree[v].begin();
       itr != tree[v].end(); ++itr) {
    int child = *itr;
    if (visited[child]) {
      continue;
    }
    path.push_back(child);
    color[child] = color[child] * -1;
    solve(child);
    if (color[child] == -1) {
      color[child] = 1;
      path.push_back(v);
      path.push_back(child);
    } else {
      color[v] = color[v] * -1;
    }
    path.push_back(v);
  }
}
int main() {
  int n;
  cin >> n;
  tree = vector<std::list<int> >(n + 1);
  color = vector<int>(n + 1);
  visited = vector<int>(n + 1, 0);
  path.reserve(10000000);
  for (int i = 1; i <= n; ++i) {
    cin >> color[i];
  }
  for (int i = 1; i < n; ++i) {
    int v, u;
    cin >> v >> u;
    tree[v].push_back(u);
    tree[u].push_back(v);
  }
  path.push_back(1);
  solve(1);
  if (color[1] == -1) {
    path.pop_back();
  }
  for (int i = 0; i < path.size(); ++i) {
    if (i) {
      cout << " ";
    }
    cout << path[i];
  }
  cout << endl;
  return 0;
}
