This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x  << " = " << x << endl; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 2e5 + 25;
const ll inf = 2e9 + 0;
const ll mod = 998244353;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
 
using namespace std;
ll n, m, s[maxn];
vector <ll> g[maxn];
ll ans[maxn];
struct DSU
{
	ll par[maxn];
	vector <ll> zxc[maxn];
	ll sum[maxn];
	void init ()
	{
		for (ll i = 1; i <= n; ++i)
		{
			par[i] = i;
			sum[i] = s[i];
			zxc[i].pb(i);
		}
	}
	ll find_set (ll v)
	{
		if (v == par[v]) return v;
		else return par[v] = find_set(par[v]);
	}
	void union_sets(ll u, ll v)
	{
		u = find_set(u);
		v = find_set(v);
		if (u == v) return;
		if (sz(zxc[u]) < sz(zxc[v]))
		{
			swap(u, v);
		}
		for (ll qq : zxc[v]) zxc[u].pb(qq);
		zxc[v].clear();
		par[v] = u;
		sum[u] += sum[v];
	} 
	ll get_sum (ll v)
	{
		v = find_set(v);
		return sum[v];
	}
	void clear (ll v)
	{
		v = find_set(v);
		zxc[v].clear();
	}
	void last_dance (ll v)
	{
		for (ll to : zxc[v])
		{
			ans[to] = 1;
		}
	}
	void out ()
	{
		for (ll i = 1; i <= n; ++i)
		{
			cout << sum[i] << ' ' << sz(zxc[i]) << nl;
		}
	}
} dsu;
void ma1n (/* SABR */)
{
	cin >> n >> m;
	vector <pair <ll, ll> > ord;
	for (ll i = 1; i <= n; ++i)
	{
		cin >> s[i];
		ord.pb({s[i], i});
	}
	for (ll i = 1, u, v; i <= m; ++i)
	{
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);	
	}
	dsu.init();
	sort(ord.begin(), ord.end());
	for (auto i : ord)
	{
		ll v = i.ss;
		for (ll to : g[v])
		{
			if (s[to] <= s[v])
			{
				if (dsu.get_sum(to) < s[v])
				{
					dsu.clear(to);
				}
				dsu.union_sets(v, to);
			}
		}
	}
	dsu.last_dance(dsu.find_set(ord.back().ss));
	for (ll i = 1; i <= n; ++i) cout << ans[i];
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;	
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << ' ';
        ma1n();
    }
    return 0;
}
| # | 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... |