#include <bits/stdc++.h>
using namespace std;
int n;
int c[200010];
int dp[200010];
vector<int> MAP[200010];
vector<int> vec;
void pre(int u, int f) {
  for (unsigned int i = 0; i < MAP[u].size(); i++) {
    int v = MAP[u][i];
    if (v == f) continue;
    pre(v, u);
    dp[u] += dp[v];
  }
  dp[u] += c[u];
}
void dfs(int u, int f) {
  while (dp[u] > 0) {
    if (u == 1 && dp[u] == 1 && c[u] == 1) {
      int v;
      for (unsigned int i = 0; i < MAP[u].size(); i++) {
        v = MAP[u][i];
        if (v != f) break;
      }
      vec.push_back(v);
      vec.push_back(1);
      vec.push_back(v);
      return;
    } else if (dp[u] == 1 && c[u] == 1)
      return;
    for (unsigned int i = 0; i < MAP[u].size(); i++) {
      int v = MAP[u][i];
      if (v == f) continue;
      if (dp[v] > 0) {
        dp[u] -= dp[v];
        vec.push_back(v);
        if (c[v]) {
          c[v] = 0;
          dp[v]--;
        } else {
          c[v] = 1;
          dp[v]++;
        }
        dfs(v, u);
        vec.push_back(u);
        dp[u] += dp[v];
        if (c[u]) {
          c[u] = 0;
          dp[u]--;
        } else {
          c[u] = 1;
          dp[u]++;
        }
      }
    }
  }
}
int main() {
  n--;
  scanf("%d", &n);
  int u, v;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &u);
    if (u == -1)
      c[i] = 1;
    else
      c[i] = 0;
  }
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    MAP[u].push_back(v);
    MAP[v].push_back(u);
  }
  pre(1, 0);
  dfs(1, 0);
  printf("1");
  for (unsigned int i = 0; i < vec.size(); i++) printf(" %d", vec[i]);
  puts("");
  return 0;
}
