#include <bits/stdc++.h>
using namespace std;
deque<int> graph[200000];
int col[200000];
int done[200000];
deque<int> ans;
int cnt;
int dfs1(int u, int prev) {
  done[u] = (col[u] == 1 ? 1 : 0);
  for (int i = 0; i < graph[u].size(); i++) {
    int v = graph[u][i];
    if (v == prev) continue;
    done[u] &= dfs1(v, u);
  }
  return done[u];
}
void dfs2(int u, int prev) {
  for (int i = 0; i < graph[u].size(); i++) {
    int v = graph[u][i];
    if (done[v] || v == prev) continue;
    ans.push_back(v);
    col[v] *= -1;
    cnt -= col[v];
    if (cnt == 0) return;
    dfs2(v, u);
    if (cnt == 0) return;
    ans.push_back(u);
    col[u] *= -1;
    cnt -= col[u];
    if (cnt == 0) return;
    if (col[v] == -1) {
      ans.push_back(v);
      col[v] *= -1;
      cnt -= col[v];
      if (cnt == 0) return;
      ans.push_back(u);
      col[u] *= -1;
      cnt -= col[u];
      if (cnt == 0) return;
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) done[i] = 0;
  cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> col[i];
    if (col[i] == -1) cnt++;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  dfs1(0, -1);
  dfs2(0, -1);
  if (col[0] == -1) {
    int v = graph[0][0];
    ans.push_back(v);
    ans.push_back(0);
    ans.push_back(v);
  }
  ans.push_front(0);
  for (int i = 0; i < ans.size(); i++) {
    if (i) cout << " ";
    cout << ans[i] + 1;
  }
  cout << endl;
  return 0;
}
