#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
int n, color[N];
vector<int> g[N];
void dfs(int v, int parent) {
  cout << v << ' ';
  for (int i = 0; i < (int)g[v].size(); ++i) {
    int to = g[v][i];
    if (to == parent) {
      continue;
    }
    color[to] = color[to] ^ 1;
    dfs(to, v);
    color[v] = color[v] ^ 1;
    cout << v << ' ';
    if (!color[to]) {
      color[to] = color[to] ^ 1;
      color[v] = color[v] ^ 1;
      cout << to << ' ' << v << ' ';
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int clr;
    cin >> clr;
    if (clr == -1)
      color[i] = 0;
    else
      color[i] = 1;
  }
  for (int i = 1; i <= n - 1; ++i) {
    int c, d;
    cin >> c >> d;
    g[c].push_back(d);
    g[d].push_back(c);
  }
  dfs(1, -1);
  if (!color[1]) {
    cout << g[1][0] << " 1 " << g[1][0];
  }
  return 0;
}
