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<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map>
#include<numeric>
#include<tuple>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define int long long
#define ss second
#define ff first
#define endl '\n'
typedef pair<int,int> pp;
void solve(){
int n,m; cin>>n>>m;
if(n<=2000&&m<=2000){
vector<int> v[n+1],s(n+1);
for(int i=1; i<=n; i++) cin>>s[i];
for(int i=1; i<=m; i++){
int a,b; cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
}
int need=0;
vector<int> dp(n+1);
for(int i=1; i<=n; i++){
priority_queue<pp,vector<pp>,greater<pp> > q;
vector<bool> vis(n+1);
q.push({s[i],i});
need+=s[i];
vis[i]=1;
while(!q.empty()){
int w=q.top().ff;
int a=q.top().ss;
if(w>dp[i]&&a!=i) break;
dp[i]+=w;
q.pop();
for(auto node: v[a]){
if(!vis[node]){
vis[node]=1;
q.push({s[node],node});
}
}
}
}
for(int i=1; i<=n; i++){
if(dp[i]==need) cout<<1;
else cout<<0;
}
}else{
vector<int> dp(n+1),s(n+1),p(n+1);
for(int i=1; i<=n; i++){
cin>>s[i];
dp[i]=s[i];
}
for(int i=1; i<=m; i++){
int a,b; cin>>a>>b;
if(a>b) swap(a,b);
dp[a]+=s[b];
p[b]=a;
}
for(int i=2; i<=n; i++){
if(dp[i]==dp[p[i]]) dp[p[i]]+=dp[i]-s[i];
if(dp[i]>=dp[p[i]]) dp[i]+=dp[p[i]];
else dp[p[i]]+=dp[i]-s[i];
}
for(int i=1; i<=n; i++){
if(dp[i]>=s[1]) cout<<1;
else cout<<0;
}
}
}
signed main(){
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
cout<<endl;
}
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... |