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>
using namespace std;
#define int long long int
void solve() {
int n, m, po = 0;
cin >> n >> m;
vector<int> s(n+1), ans(n+1), vis(n+1, 0), proc(n+1, 0);
vector<vector<int>> adj(n+1);
for (int i = 1; i <= n; i++) {
cin >> s[i];
po += s[i];
}
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
queue<int> q;
q.push(1);
while(!q.empty()) {
int ind = q.front();
q.pop();
if (proc[ind]) {
continue;
}
proc[ind] = 1;
int inh = s[ind];
priority_queue<pair<int, int>> pq;
pq.push({0, ind});
while(!pq.empty()) {
auto [w, a] = pq.top();
pq.pop();
if (vis[a] == ind) {
continue;
}
w = abs(w);
if (inh < w) {
break;
}
inh += w;
if (ans[a]) {
ans[ind] = 1;
break;
}
vis[a] = ind;
for (int b : adj[a]) {
if (vis[b] == ind) {
continue;
}
pq.push({-s[b], b});
}
}
if (po == inh) {
ans[ind] = 1;
}
for (int j : adj[ind]) {
if (proc[j]) {
continue;
}
q.push(j);
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i];
}
cout << endl;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
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... |