#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int nax=2e5+5;
set<pair<int,int>> revadj[nax];
vector<int> adj[nax];
bool vis[nax];
int tab[nax];
bool state[nax];
long long sz[nax];
int res[nax];
vector<int> top;
bool compare(int x,int y){
return tab[x]<tab[y];
}
/*struct node{
int child,par,x,p;
};
struct compare2{
bool operator()(node const& p1, node const& p2)
{
if(p1.child!=p2.child) return p1.child < p2.child;
else return p1.par > p2.par;
}
};
void top_sort(int x){
vis[x]=true;
for(auto u:adj[x])
{
if(vis[u]) continue;
top_sort(x);
}
top.pb(x);
}*/
void dfs(int x,int p){
sz[x]=tab[x];
for(auto u:adj[x]){
if(u==p) continue;
dfs(u,x);
sz[x]+=sz[u];
}
if(p!=-1){
if(sz[x]>=tab[p]) state[x]=1;
else state[x]=0;
}
}
void ans(int x,int p){
if(state[x]==0) return;
res[x]=1;
for(auto u:adj[x]){
if(u==p) continue;
ans(u,x);
}
}
int main() {
int n,m;
cin>>n>>m;
pair<int,int> mx={-1,-1};
vector<pair<int,int>> cur(n);
for (int i = 0; i < n; ++i)
{
cin>>tab[i];
cur[i]={tab[i],i};
if(mx.fi<tab[i]){
mx={tab[i],i};
}
}
for (int i = 0; i < m; ++i)
{
int x,y;
cin>>x>>y;
x--;y--;
if(tab[x]==tab[y]){
revadj[x].insert({tab[y],y});
revadj[y].insert({tab[x],x});
}else if(tab[x]>tab[y]){
revadj[y].insert({tab[x],x});
}else{
revadj[x].insert({tab[y],y});
}
}
sort(cur.begin(),cur.end());
set<pair<int,int>> nab;
for (int i = 0; i < n; ++i)
{
if(vis[cur[i].se]) continue;
set<int> a;
int b=cur[i].se;
a.insert(b);
for(auto u:revadj[b]){
if(a.count(u.se)) continue;
nab.insert(u);
}
while(true){
for(auto u:revadj[b]){
if(a.count(u.se)) continue;
nab.insert(u);
}
if(nab.size()==0) break;
int ne=nab.begin()->se;
vis[ne]=true;
nab.erase(*nab.begin());
a.insert(ne);
adj[ne].pb(b);
adj[b].pb(ne);
b=ne;
}
}
state[mx.se]=true;
dfs(mx.se,-1);
ans(mx.se,-1);
for (int i = 0; i < n; ++i)
{
cout <<res[i];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14424 KB |
Output is correct |
2 |
Correct |
5 ms |
14428 KB |
Output is correct |
3 |
Correct |
5 ms |
14556 KB |
Output is correct |
4 |
Runtime error |
337 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14424 KB |
Output is correct |
2 |
Correct |
6 ms |
14428 KB |
Output is correct |
3 |
Execution timed out |
1080 ms |
75972 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14428 KB |
Output is correct |
2 |
Incorrect |
267 ms |
43204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14428 KB |
Output is correct |
2 |
Runtime error |
576 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14424 KB |
Output is correct |
2 |
Correct |
5 ms |
14428 KB |
Output is correct |
3 |
Correct |
5 ms |
14556 KB |
Output is correct |
4 |
Runtime error |
337 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |