#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using ld = long double;
using hash_map = gp_hash_table<int, int>;
using hash_set = gp_hash_table<int, null_type>;
auto sd = std::chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(sd);
const ll maxn = 2e5+1997;
ll s[maxn];
bool use[maxn];
vector<vector<ll>> g;
void dfs(ll u, ll &sum){
use[u] = true;
sum += s[u];
for (auto v : g[u]){
if (!use[v] && sum >= s[v]){
dfs(v, sum);
}
}
}
bool cmp(ll a, ll b){
return s[a]<s[b];
}
void solve1() {
ll n, m;
cin >> n >> m;
g.resize(n+1);
for (int i = 1; i <= n; i++){
cin>>s[i];
}
for (int j = 0 ; j < m; j++){
ll u, v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int j = 1; j <= n; j++){
sort(g[j].begin(), g[j].end(),cmp);
}
for (int i =1; i <= n; i++){
for (int j =1; j <= n; j++){
use[j] = false;
}
ll sum = 0;
dfs(i, sum);
bool is = true;
for (int j = 1; j <= n; j++){
is &= use[j];
}
cout<<is;
}
cout<<endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef local
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
cout << fixed << setprecision(6);
ll t1 = 1;
//cin>>t1;
for (ll o_ = 0; o_ < t1; o_++) {
solve1();
}
#ifdef local
printf_s("\n%.5f s", (double) clock() / CLOCKS_PER_SEC);
#endif
}
# | 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... |