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;
typedef vector<int> vi;
typedef pair<int,int> ii;
const int MAX_N=2e5+10;
vector<vi> G;
int ha[MAX_N];
bool vis[MAX_N];
int n,m;
void bfs(int u){
for(int i=0;i<n;i++) vis[i]=0;
priority_queue<ii, vector<ii>, greater<ii> > q;
vis[u]=1;
ll co=ha[u];
for(auto &v:G[u]){
q.push(ii(ha[v],v));
}
while(!q.empty()){
int x=q.top().second; q.pop();
if(co<ha[x]) continue;
vis[x]=1;
co+=ha[x];
for(auto &v:G[x]){
if(!vis[v]){
q.push(ii(ha[v],v));
}
}
}
}
int main(){
cin>>n>>m;
G.resize(n+1);
for(int i=0;i<n;i++) cin>>ha[i];
for(int i=0;i<m;i++){
int a,b; cin>>a>>b;
a--; b--;
G[a].push_back(b);
G[b].push_back(a);
}
string ans="";
int r=1;
ll co=ha[0];
for(int i=0;i<n;i++){
if(i==r){
co+=ha[i]; r++;
}
while(r!=n && co>=ha[r]){
co+=ha[r];
r++;
}
if(r==n) ans+='1';
else ans+='0';
}
/*for(int i=0;i<n;i++){
bfs(i);
bool all=1;
for(int j=0;j<n;j++) all&=vis[j];
if(all) ans+='1';
else ans+='0';
}*/
cout<<ans<<endl;
}
# | 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... |