#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;
vector<int> adj[nax];
vector<int> newadj[nax];
int tab[nax];
int parent[nax];
long long sz[nax];
int ans[nax];
int find(int x){
if(parent[x]==x) return x;
return parent[x]=find(parent[x]);
}
bool sameset(int x,int y){
return find(x)==find(y);
}
void joinset(int x,int y){
x=find(x);
y=find(y);
parent[x]=y;
}
bool compare(int x,int y){
if(tab[x]!=tab[y]) return tab[x]>tab[y];
else return x>y;
}
void precompute(int x,int p){
sz[x]=tab[x];
for(auto u:newadj[x]){
if(u==p) continue;
precompute(u,x);
sz[x]+=sz[u];
}
}
void dfs(int x,int p){
for(auto u:newadj[x]){
if(u==p) continue;
if(sz[u]<tab[x]) continue;
ans[u]=1;
dfs(u,x);
}
}
int main(){
int n,m;
cin>>n>>m;
vector<pair<int,int>> cur(n);
for (int i = 0; i < n; ++i)
{
parent[i]=i;
cin>>tab[i];
cur[i]={tab[i],i};
}
for (int i = 0; i < m; ++i)
{
int x,y;
cin>>x>>y;
x--;y--;
adj[x].pb(y);
adj[y].pb(x);
}
sort(cur.begin(),cur.end());
for (int i = 0; i < n; ++i)
{
sort(adj[i].begin(),adj[i].end(),compare);
}
for (int t = 1; t < n; ++t)
{
int i=cur[t].se;
for(auto u:adj[i]){
if(tab[u]<=tab[i]&&(!sameset(i,u))){
joinset(i,u);
newadj[i].pb(u);
newadj[u].pb(i);
}
}
}
precompute(cur[n-1].se,-1);
ans[cur[n-1].se]=true;
dfs(cur[n-1].se,-1);
for (int i = 0; i < n; ++i)
{
cout <<ans[i];
}cout <<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
13400 KB |
Output is correct |
2 |
Correct |
2 ms |
13404 KB |
Output is correct |
3 |
Correct |
2 ms |
13404 KB |
Output is correct |
4 |
Incorrect |
3 ms |
13660 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
13404 KB |
Output is correct |
2 |
Correct |
2 ms |
13572 KB |
Output is correct |
3 |
Correct |
180 ms |
34336 KB |
Output is correct |
4 |
Correct |
146 ms |
33360 KB |
Output is correct |
5 |
Correct |
185 ms |
27632 KB |
Output is correct |
6 |
Correct |
188 ms |
27984 KB |
Output is correct |
7 |
Correct |
204 ms |
28244 KB |
Output is correct |
8 |
Correct |
195 ms |
27988 KB |
Output is correct |
9 |
Correct |
160 ms |
27932 KB |
Output is correct |
10 |
Correct |
166 ms |
29384 KB |
Output is correct |
11 |
Correct |
168 ms |
29584 KB |
Output is correct |
12 |
Correct |
156 ms |
27940 KB |
Output is correct |
13 |
Correct |
157 ms |
43356 KB |
Output is correct |
14 |
Correct |
148 ms |
41812 KB |
Output is correct |
15 |
Correct |
174 ms |
43600 KB |
Output is correct |
16 |
Correct |
151 ms |
43344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
13404 KB |
Output is correct |
2 |
Incorrect |
199 ms |
36376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
13400 KB |
Output is correct |
2 |
Incorrect |
212 ms |
27928 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
13400 KB |
Output is correct |
2 |
Correct |
2 ms |
13404 KB |
Output is correct |
3 |
Correct |
2 ms |
13404 KB |
Output is correct |
4 |
Incorrect |
3 ms |
13660 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |