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;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
#endif // LOCAL
int N, M;
cin >> N >> M;
vector<int> a(N);
for(int i = 0; i < N; ++i){
cin >> a[i];
}
vector<vector<int>> adj(N);
while(M--){
int u, v;
cin >> u >> v;
--u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<bool> vis(N);
auto solve = [&](int s) -> bool{
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
fill(vis.begin(), vis.end(), false);
long long have = a[s];
vis[s] = true;
for(int u : adj[s]){
if(!vis[u]){
vis[u] = true;
pq.push({a[u], u});
}
}
while(!pq.empty()){
int demand, u;
tie(demand, u) = pq.top(); pq.pop();
if(demand > have) return false;
have += demand;
for(auto v : adj[u]){
if(!vis[v]){
vis[v] = true;
pq.push({a[v], v});
}
}
}
return true;
};
for(int i = 0; i < N; ++i){
cout << solve(i);
}
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... |