#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const long long infl = 9e18;
vector<vector<int> > graph;
vector<int> col, ans;
void DFS(int s, int p) {
  for (int to : graph[s]) {
    if (to == p) continue;
    ans.push_back(to);
    col[to] = -col[to];
    DFS(to, s);
    ans.push_back(s);
    col[s] = -col[s];
  }
  if (col[s] == -1) {
    if (s == 0)
      ans.pop_back();
    else {
      ans.push_back(p);
      col[p] = -col[p];
      ans.push_back(s);
      col[s] = -col[s];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  scanf("%d", &n);
  col.resize(n);
  graph.resize(n);
  for (int i = 0; i < n; i++) scanf("%d", &col[i]);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  cout << "1 ";
  DFS(0, -1);
  for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 << ' ';
}
