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 <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define UseOFF ios_base::sync_with_stdio(0);cin.tie(0), cout.tie(0);
#define sz size
#define ins insert
#define new junkedseduneon
#define prev usfdjik
const ll N = 2e6 + 111;
ll a[N];
vector <ll> v[N];
bool used[N];
bool used2[N];
ll sum[N];
ll r[N];
bool ans[N];
void dfs(ll x, ll p) {
used[x] = 1;
sum[x] = a[x] + sum[p];
for(auto to : v[x]) {
if(to > x || v[to].sz() > 2) {
continue;
}
dfs(to, x);
}
}
void dfs2(ll x, ll p) {
used[x] = 1;
sum[x] = a[x] + sum[p];
for(auto to : v[x]) {
if(used[to]) continue;
if(to > x) {
return;
}
dfs(to, x);
}
}
void solve() {
ll n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= m; i++) {
ll x, y;
cin >> x >> y;
if(x < y) swap(x, y);
v[x].pb(y);
v[y].pb(x);
}
// if(n <= 2 && m <= 2) {
// for(int i = 1; i <= n; i++) {
// multiset < pair <ll, ll> > st;
// st.ins({a[i], i});
// //cout << x.ff << " " << x.ss << '\n';
// ll cur = 0;
// bool bb = 0;
// for(int j = 1; j <= n; j++) used[j] = 0;
// used[i] = 1;
// while(st.sz() > 0) {
// vector <ll> g;
// pair <ll, ll> x = *st.begin();
// if(cur < x.ff && x.ss != i) {
// cout << '0';
// bb = 1;
// break;
// }
// cur += x.ff;
// for(auto to : v[x.ss]) {
// if(used[to]) continue;
// //cout << i << " " << cur << " " << to << " " << x.ss << endl;
// st.ins({a[to], to});
// used[to] = 1;
// }
// st.erase(x);
// }
// if(st.sz() == 0) {
// cout << '1';
// }
// }
// return;
// }
for(int i = n; i >= 1; i--) {
if(sum[i] == 0) {
sum[i] = a[i];
for(auto to : v[i]) {
if(to > i) sum[i] += sum[to];
}
dfs(i, i);
}
}
ans[1] = 1;
for(int i = 2; i <= n; i++) {
for(auto to : v[i]) {
if(to > i) continue;
if(ans[to] == 1) {
if(sum[i] >= a[to]) {
ans[i] = 1;
}
else {
r[i] = a[to] - sum[i];
}
}
}
}
for(int i = 1; i <= n; i++) {
cout << ans[i];
}
}
signed main()
{
UseOFF
ll ttt = 1;
//cin >> ttt;
while(ttt--)
{
solve();
}
}
# | 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... |