#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T Gcd(T a, T b) {
  if (a < 0) return Gcd(-a, b);
  if (b < 0) return Gcd(a, -b);
  return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
  if (a < 0) return Lcm(-a, b);
  if (b < 0) return Lcm(a, -b);
  return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
  long long ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
template <typename T>
long long int isLeft(T a, T b, T c) {
  return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);
}
long long ModInverse(long long number, long long MOD) {
  return Bigmod(number, MOD - 2, MOD);
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream second(s);
  second >> sm;
  return sm;
}
vector<int> A[210007];
vector<int> an;
int a[210007];
int Cnt[210007];
void Dekhi(int u, int p) {
  Cnt[u] = (a[u] == 0);
  for (int i = 0; i < A[u].size(); i++) {
    int v = A[u][i];
    if (v == p) continue;
    Dekhi(v, u);
    Cnt[u] += Cnt[v];
  }
}
int dp[210007];
int Okk(int v, int c) {
  if (v % 2 && c == 0) return 0;
  if (v % 2 == 0 && c == 1) return 0;
  return 1;
}
void Dfs(int u, int p, long long int lagbe, int Pr) {
  dp[u] = 1;
  an.push_back(u);
  int k = 0;
  for (int i = 0; i < A[u].size(); i++) {
    int v = A[u][i];
    if (v == p) continue;
    if (Cnt[v]) {
      k++;
    }
  }
  int kp = k;
  for (int i = 0; i < A[u].size(); i++) {
    int v = A[u][i];
    if (v == p) continue;
    if (Cnt[v]) {
      k--;
      Dfs(v, u, (lagbe + k + Okk(dp[u], a[u])), Okk(dp[u], a[u]));
    }
  }
  if (a[u] == 1 && p) {
    if (dp[u] % 2) {
      an.push_back(p);
      an.push_back(u);
      dp[p]++;
      if (Okk(dp[p], a[p]))
        ;
      else
        lagbe--;
    }
  } else if (p && !a[u]) {
    if (dp[u] % 2 == 0) {
      an.push_back(p);
      an.push_back(u);
      dp[p]++;
      if (Okk(dp[p], a[p]))
        lagbe++;
      else
        lagbe--;
    }
  }
  if (lagbe && p) {
    an.push_back(p);
    dp[p]++;
  }
}
int main() {
  int n;
  n = in<int>();
  long long int cnt = 0;
  for (int i = 1; i < n + 1; i++) {
    a[i] = in<int>();
    if (a[i] == -1) {
      if (i == 1) {
        cnt++;
      } else
        cnt -= 1000000;
    }
    if (a[i] == -1) a[i] = 0;
  }
  a[1] ^= 1;
  for (int i = 1; i < n; i++) {
    int a, b;
    a = in<int>(), b = in<int>();
    A[a].push_back(b);
    A[b].push_back(a);
  }
  if (cnt == 1) {
    for (int i = 0; i < A[1].size(); i++) {
      int v = A[1][i];
      cout << 1 << " " << v << " " << 1 << " " << v << endl;
    }
    return 0;
  }
  Dekhi(1, 0);
  Dfs(1, 0, 0, 0);
  if (an.size() > 1e7) assert(0);
  for (int i = 0; i < an.size(); i++) printf("%d ", an[i]);
  return 0;
}
