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
#define oo 100000000000000000
const int mx = 2005;
int s[mx];
vector<int> g[mx];
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n,m; cin >> n >> m;
for(int i = 1; i <= n; ++i) {
cin >> s[i];
}
for(int i = 1; i <= m; ++i) {
int u,v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1; i <= n; ++i) {
priority_queue<pair<int,int>> pq;
vector<bool> used(n + 1, 0);
used[i] = true;
int val = s[i];
for(int v : g[i]) {
pq.push({-s[v], v});
}
while(!pq.empty() && -pq.top().first <= val) {
int v = pq.top().second;
used[v] = 1;
val += (-pq.top().first);
pq.pop();
for(int go : g[v]) {
if(!used[go]) {
pq.push({-s[go], go});
}
}
}
int cnt = 0;
for(int j = 1; j <= n; ++j) {
cnt += used[j];
}
if(cnt == n) {
cout << "1";
} else {
cout << "0";
}
}
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... |