#include <bits/stdc++.h>
using namespace std;
const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
vector<int> e[N];
int n, m, K;
int col[N];
void dfs(int u, int fa) {
  for (int i = 0; i < e[u].size(); ++i) {
    int v = e[u][i];
    if (v == fa) continue;
    col[v] = -col[v];
    cout << v << ' ';
    dfs(v, u);
    col[u] = -col[u];
    cout << u << ' ';
    if (col[v] == -1) {
      col[v] = -col[v];
      cout << v << ' ';
      col[u] = -col[u];
      cout << u << ' ';
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> col[i];
  }
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  cout << 1 << ' ';
  dfs(1, 0);
  if (col[1] == -1) {
    cout << e[1][0] << ' ';
    cout << 1 << ' ';
    cout << e[1][0] << ' ';
  }
  return 0;
}
