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 N = 2e5 + 5;
vector<int> g[N];
int a[N], n, m;
int main()
{
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) {
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++) {
ll cur = a[i], cnt = 0;
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> q;
q.push({a[i], i});
vector<bool> vis(n);
vis[i] = 1;
while(!q.empty()) {
auto [val, v] = q.top(); q.pop();
if(v != i) {
if(cur < val) {
break;
} else {
cur += val;
}
}
cnt++;
for(auto u : g[v]) {
if(!vis[u]) {
vis[u] = 1;
q.push({a[u], u});
}
}
}
cout << (cnt == n ? '1' : '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... |