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>
typedef long long int ll;
typedef long double ld;
#define INF (int)(1e9 + 7)
#define INF2 998244353
#define N (ll)(2e5 + 5)
//#define f first
//#define s second
#define int ll
#define lsb(x) (x & (-x))
using namespace std;
int n, m, g, h;
int ans[N], a[N];
vector<int> v[N];
bool used[2005][2005];
void solve(){
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int i=1; i<=m; i++){
cin >> g >> h;
v[g].push_back(h);
v[h].push_back(g);
}
for(int i=1; i<=n; i++){
int cur = 0, cursz=a[i];
priority_queue<pair<int, int>> pq;
pq.push({-a[i], i});
while(!pq.empty()){
auto p = pq.top();
pq.pop();
int j = p.second;
if(used[i][j])continue;
if(cursz < a[j])continue;
if(j != i)cursz += a[j];
for(int u : v[j]){
pq.push({-a[u], u});
}
used[i][j] = 1;
cur++;
for(int u : v[j]){
if(!used[i][u]){
pq.push({-a[u], u});
}
}
}
ans[i] = cur == n;
//cout << cur << ' ';
}
for(int i=1; i<=n; i++){
cout << ans[i];
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin>>T;
for(int i=1; i<=T; i++){
solve();
}
}
# | 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... |