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;
int main(){
int n,m; cin >> n >> m;
vector<long long> a(n+1); for(int i = 1; i <= n; ++i) cin >> a[i];
vector<vector<int>> g(n+1);
for(int i = 0; i < m; ++i){
int x,y; cin >> x >> y;
g[x].emplace_back(y);
g[y].emplace_back(x);
}
vector<int> vis(n+1,0);
for(int i = 1; i <= n; ++i){
set<pair<long long,int>> st;
st.insert({0,i}); vis[i] = i;
long long cur = 0;
while(!st.empty()){
auto [cnt,x] = *st.begin();
if(cnt > cur) break;
st.erase(st.begin());
cur += a[x];
for(int z: g[x]){
if(vis[z] != i) {
vis[z] = i;
st.insert({a[z],z});
}
}
}
if(st.empty()) cout << 1;
else cout << 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... |