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 int64_t
#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
vector<int> G[2009];
int tab[2009];
bool vis[2009];
int cnt;
bool ans[2009];
void bfs(int x) {
priority_queue<pii, vector<pii>, greater<pii>> Q;
vis[x] = true;
Q.push({0, x});
int sum = 0;
while(sz(Q)&&Q.top().st<=sum) {
cnt++;
int y = Q.top().nd;
Q.pop();
sum += tab[y];
for(int z:G[y]) {
if(!vis[z]) {
vis[z] = true;
Q.push({tab[z], z});
}
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for(int i=1;i<=n;i++) {
cin >> tab[i];
}
for(int i=0;i<m;i++) {
int a, b;
cin >> a >> b;
G[a].pb(b);
G[b].pb(a);
}
for(int i=1;i<=n;i++) {
cnt = 0;
memset(vis, 0, sizeof(vis));
bfs(i);
if(cnt==n) ans[i] = true;
}
for(int i=1;i<=n;i++) cout << ans[i];
cout << "\n";
}
# | 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... |