#include <bits/stdc++.h>
#pragma GCC optimize("O0")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
long long n, m, a, b, c, k, temp, x, y;
const int MAXN = 100000 + 11;
inline void read(vector<long long> &v);
inline long long max(long long a, long long b);
inline long long min(long long a, long long b);
inline long long gcd(long long a, long long b);
void storepowers(int n, vector<int> &a);
vector<long long> v[MAXN];
int val[MAXN];
vector<long long> inv[MAXN];
bool from[MAXN][3];
void multibfs(int index) {
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (val[i] == index) {
      q.push(i);
    }
  }
  while (!q.empty()) {
    int f = q.front();
    from[f][index] = 1;
    q.pop();
    if (index == 1) {
      for (auto x : v[f]) {
        if (!from[x][index]) {
          from[x][index] = 1;
          q.push(x);
        }
      }
    } else {
      for (auto x : inv[f]) {
        if (!from[x][index]) {
          from[x][index] = 1;
          q.push(x);
        }
      }
    }
  }
}
void solveforthiscase(const int &test) {
  if (0) cout << "Case #" << test << ':' << '\n';
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> val[i];
  while (m--) {
    cin >> a >> b;
    if (val[b] != 1) {
      v[a].push_back(b);
      inv[b].push_back(a);
    }
  }
  multibfs(1);
  multibfs(2);
  for (int i = 1; i <= n; i++) {
    if (from[i][1] && from[i][2])
      cout << 1 << ' ';
    else
      cout << 0 << ' ';
    cout << '\n';
  }
  if (0) cout << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  for (int i = 1; i <= test; i++) {
    solveforthiscase(i);
  }
}
void storepowers(int n, vector<int> &a) {
  a.resize(n + 1);
  a[0] = 1;
  for (int i = 1; i <= n; i++) a[i] = a[i - 1] * 2;
  return;
}
inline long long max(long long a, long long b) { return ((a > b) ? a : b); }
inline long long min(long long a, long long b) { return ((a > b) ? b : a); }
inline long long gcd(long long a, long long b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
inline void read(vector<long long> &v) {
  for (int i = 0; i < v.size(); i++) cin >> v[i];
}
