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;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 100500;
int n;
vector<int> g[N];
int s[N];
bool check(int v){
queue<int> q;
q.push(v);
vector<bool> used(n, false);
used[v] = true;
ll sum = 0;
set<pair<int, int>> blocked;
while (!q.empty()){
v = q.front();
q.pop();
sum += s[v];
while (!blocked.empty() && blocked.begin()->first <= sum){
int x = blocked.begin()->second;
q.push(x);
used[x] = true;
blocked.erase(blocked.begin());
}
for (int u : g[v]){
if (used[u]) continue;
if (s[u] <= sum){
q.push(u);
used[u] = true;
} else {
blocked.emplace(s[u], u);
}
}
}
return count(all(used), true) == n;
}
void solve(){
int m;
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> s[i];
}
while (m--){
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 0; i < n; i++){
cout << check(i);
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
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... |