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;
typedef long long ll;
const int maxn = 2e3;
int n, m;
vector<ll> a(maxn+5);
vector<vector<int>> g(maxn+5);
vector<bool> vis(maxn+5, 0);
bool test(int V){
for(int i = 0; i < maxn+5; i++)
vis[i] = 0;
priority_queue<array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> PQ;
int took = 0;
ll curr_size = 0;
PQ.push({0, V});
while(!PQ.empty()){
int v = PQ.top()[1];
PQ.pop();
if(vis[v])
continue;
vis[v] = 1;
if(V!=v && a[v] > curr_size){
return 0;
}
took++;
curr_size+= a[v];
for(int u : g[v]){
if(!vis[u]){
PQ.push({a[u], u});
}
}
}
return (took == n);
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for(int i = 1; i <= n; i++)
cout << test(i);
cout << "\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
// cin >> tt;
while(tt--){
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... |