#include <bits/stdc++.h>
using namespace std;
int Total;
int Array[200001];
int Count;
int Link[200001], Next[400001], Son[400001];
inline void Add(int U, int V) {
  Count++;
  Son[Count] = V;
  Next[Count] = Link[U];
  Link[U] = Count;
}
inline void Dfs(int U, int Fa) {
  register int j;
  for (j = Link[U]; j; j = Next[j]) {
    if (Son[j] != Fa) {
      cout << ' ' << Son[j];
      Array[Son[j]] ^= 1;
      Dfs(Son[j], U);
      cout << ' ' << U;
      Array[U] ^= 1;
    }
  }
  if (U == 1) {
    if (!Array[U]) {
      Array[U] ^= 1;
      cout << ' ' << Son[Link[U]] << ' ' << U << ' ' << Son[Link[U]];
    }
  } else {
    if (!Array[U]) {
      Array[U] ^= 1;
      Array[Fa] ^= 1;
      cout << ' ' << Fa << ' ' << U;
    }
  }
}
int main(void) {
  register int i;
  cin >> Total;
  for (i = 1; i <= Total; i++) {
    cin >> Array[i];
    if (Array[i] == -1) {
      Array[i] = 0;
    }
  }
  for (i = 1; i < Total; i++) {
    register int U, V;
    cin >> U >> V;
    Add(U, V);
    Add(V, U);
  }
  cout << 1;
  for (i = 1; i <= Total; i++) {
    if (!Array[i]) {
      Dfs(1, 0);
      break;
    }
  }
  return 0;
}
