#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll , ll> llll;
#define fi first
#define sec second
#define all(x) x.begin() , x.end()
#define pb push_back
const ll ous = 2e5+7;
std::vector<llll> ar ;std::vector<ll> adj[ous] , nds(ous , 0) , par(ous) , sz(ous) , ans(ous , 1) , rar(ous) , kr(ous) , ant(ous);
ll n , m , o;
ll fin(ll x){
if(par[x] == x){
return x;
}
return par[x] = fin(par[x]);
}
void mrg(ll x , ll y){
x = fin(x);y = fin(y);
if(sz[y] > sz[x]){
std::swap(x , y);
}
if(x != y){
par[y] = x;
sz[x] += sz[y];
}
}
void dfs(ll crt){
o += rar[crt];
nds[crt] = 1;
for(auto j:adj[crt]){
if(fin(crt) != fin(j) && nds[j] == 0){
mrg(crt , j);
dfs(j);
}
}
}
void solve(){
ll n , m;std::cin >> n >> m;
ar.resize(n);
for(ll i = 0;n>i;i++){
std::cin >> ar[i].fi;
ar[i].sec = i + 1;
rar[i+1] = ar[i].fi;
}
for(ll i = 0;m>i;i++){
ll x , y;std::cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
}
std::sort(all(ar) , std::greater<llll>());
ll ik = 1;
for(;n > ik;ik++){
if(ar[ik].fi != ar[ik-1].fi){
break;
}
}
while(n > ik){
for(ll i = 0;n>+i;i++){
par[i] = i;
sz[i] = 1;
nds[i] = 0;
kr[i] = 0;
ant[i] = 0;
}
for(ll i = 0;ik>i;i++){
nds[ar[i].sec] = 1;
}
for(ll i = ik;n>i;i++){
ans[ar[i].sec] = 0;
}
for(ll i = 1;n>+i;i++){
if(nds[i] == 0){
dfs(i);
kr[fin(i)] = o;
o = 0;
}
}
for(ll i = 0;ik>i;i++){
for(auto j:adj[ar[i].sec]){
ll ff = fin(j);
if(kr[ff] >= ar[i].fi){
ant[ff] |= ans[ar[i].sec];
}
}
}
for(ll i = 1;n>+i;i++){
ans[i] |= ant[fin(i)];
}
ik++;
for(;n > ik;ik++){
if(ar[ik-1].fi != ar[ik].fi){
break;
}
}
}
for(ll i = 1;n>=i;i++){
std::cout << ans[i];
}
std::cout <<"\n";
}
signed main(){
std::ios_base::sync_with_stdio(false);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15956 KB |
Output is correct |
2 |
Correct |
9 ms |
15956 KB |
Output is correct |
3 |
Correct |
9 ms |
15952 KB |
Output is correct |
4 |
Incorrect |
130 ms |
16212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
15972 KB |
Output is correct |
2 |
Correct |
8 ms |
15956 KB |
Output is correct |
3 |
Execution timed out |
1066 ms |
38472 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15956 KB |
Output is correct |
2 |
Execution timed out |
1066 ms |
40804 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15956 KB |
Output is correct |
2 |
Correct |
509 ms |
29988 KB |
Output is correct |
3 |
Correct |
448 ms |
30056 KB |
Output is correct |
4 |
Correct |
523 ms |
30124 KB |
Output is correct |
5 |
Correct |
210 ms |
30112 KB |
Output is correct |
6 |
Correct |
161 ms |
29756 KB |
Output is correct |
7 |
Incorrect |
169 ms |
30668 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15956 KB |
Output is correct |
2 |
Correct |
9 ms |
15956 KB |
Output is correct |
3 |
Correct |
9 ms |
15952 KB |
Output is correct |
4 |
Incorrect |
130 ms |
16212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |