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;
vector<vector<int> > g;
vector<int> s;
vector<bool> used;
class Compare{
public:
bool operator () (int a, int b){
return s[a] > s[b];
}
};
priority_queue<int, vector<int>, Compare> b;
int n;
char bfs(int u){
used.assign(n+1, false);
int cnt = s[u];
used[u] = true;
for(int v: g[u]){
b.push(v);
used[u] = true;
}
while(!b.empty()){
u = b.top();
// cout << s[u] << ' ';
b.pop();
if(s[u] > cnt) return '0';
cnt += s[u];
for(int v: g[u]){
if(!used[v]){
b.push(v);
used[v] = true;
}
}
}
return '1';
}
int main(){
int m;
cin >> n >> m;
s.resize(n+1);
g.resize(n+1);
for(int i = 1; i <= n; ++i) cin >> s[i];
for(int i = 0, u, v; i < m; ++i){
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
// for(int i = 1; i <= n; ++i){
// sort(g[i].begin(), g[i].end(), [&](int a, int b){
// return s[a] < s[b];
// });
// }
for(int i = 1; i <= n; ++i) cout << bfs(i);
}
# | 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... |