#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200001];
bool b[200001];
void dfs(int u, int p) {
  cout << u << " ";
  b[u] = !b[u];
  for (auto v : adj[u]) {
    if (v != p) {
      dfs(v, u);
      cout << u << " ";
      b[u] = !b[u];
    }
  }
  if (u != 1 && !b[u]) {
    cout << p << " " << u << " ";
    b[p] = !b[p];
    b[u] = 1;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, u, v, c;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c;
    b[i] = c == 1;
  }
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  b[1] = !b[1];
  dfs(1, 0);
  if (!b[1]) cout << adj[1][0] << " 1 " << adj[1][0];
  cout << "\n";
  return 0;
}
