/*
_ __ __ __ ____ ___ _ __
| | /| / / ___ _ / /_ ____ / / / __ \ ___ ___ / _ \ (_) ___ ____ ___ / /
| |/ |/ / / _ `// __// __/ / _ \ / /_/ / / _ \/ -_) / ___/ / / / -_)/ __// -_) /_/
|__/|__/ \_,_/ \__/ \__/ /_//_/ \____/ /_//_/\__/ /_/ /_/ \__/ \__/ \__/ (_)
*/
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define all(v, l) v.begin() + l, v.end()
#define rall(v, l) v.rbegin(), v.rend() - l
#define pb push_back
#define rsz resize
#define fi first
#define se second
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define endl "\n"
#define newline cout << endl;
using namespace std;
// constants
// functions
ll GCD(ll A, ll B);
ll LCM(ll A, ll B);
ll power(ll base, ll exponent);
// structs
struct graph
{
vector <ll> lvl;
vector <int> par;
vector <vector <int> > g;
void prep(int n)
{
par.rsz(n);
g.rsz(n);
lvl.rsz(n);
}
void add(int u, int v)
{
g[u].pb(v);
g[v].pb(u);
}
int get(int v)
{
if (par[v] == v)
{
return v;
}
return par[v] = get(par[v]);
}
void merge(int u, int v)
{
lvl[u] += lvl[v];
par[v] = u;
}
void cleanse()
{
iota(all(par, 0), 0);
}
};
// globals
// variables
int n, m;
// iterators
int i;
// notes
/*
One piece on top!
-stuff you should look for-
* int overflow, array bounds
* special cases (n=1?)
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
continue - skip the rest in the loop
*/
void solve()
{
graph G;
cin >> n >> m;
G.prep(n + 1);
vector <pair <int, int> > v(n + 1);
for (i = 1; i <= n; i++)
{
cin >> v[i].fi;
G.lvl[i] = 1LL * v[i].fi;
v[i].se = i;
}
for (i = 1; i <= m; i++)
{
int a, b;
cin >> a >> b;
G.add(a, b);
}
G.cleanse();
sort(all(v, 1));
vector <bool> ok(n + 1, false);
vector <vector <int> > nw(n + 1);
for (auto [d, a] : v)
{
ok[a] = true;
for (auto b : G.g[a])
{
if (!ok[b])
{
continue;
}
b = G.get(b);
if (b == a)
{
continue;
}
nw[a].pb(b);
G.merge(a, b);
}
}
int c = v[n].se;
vector <int> win(n + 1, 0);
for (i = 1; i <= n; i++)
{
swap(v[i].fi, v[i].se);
}
sort(all(v, 1));
function<void(int, int)> DFS = [&](int k, int b)
{
win[k] = b;
for (auto u : nw[k])
{
DFS(u, (b && (G.lvl[u] >= 1LL * v[k].se)));
}
};
DFS(c, true);
for (i = 1; i <= n; i++)
{
cout << win[i];
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
newline
}
}
int GCD(int A, int B)
{
if (!A)
{
return B;
}
return GCD(B % A, A);
}
int LCM(int A, int B)
{
return A * B / GCD(A, B);
}
int power(int base, int exponent)
{
int res = 1;
while (exponent)
{
if (exponent & 1)
{
res *= base;
}
base *= base;
exponent >>= 1;
}
return res;
}
/*
$$$$$$$$\ $$$$$$$$\
$$ _____|\____$$ |
$$ | $$ /
$$$$$\ $$ /
$$ __| $$ /
$$ | $$ /
$$$$$$$$\ $$$$$$$$\
\________|\________|
*/
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |