#include <bits/stdc++.h>
#define int long long
using namespace std;
const int NS = (int)4e5 + 4;
int n, m;
int a[NS];
vector<int> way[NS], way2[NS];
int pr[NS], mesum[NS], chk[NS], ans[NS];
set<pair<int, int>> st[NS];
int nodeN;
int fd(int x){
assert(x != 0);
return (x == pr[x] ? x : pr[x] = fd(pr[x]));
}
void unite(int x, int y){
x = fd(x), y = fd(y);
if(x == y) return;
if((int)st[x].size() > (int)st[y].size()){
swap(x, y);
}
pr[x] = y;
mesum[y] += mesum[x];
for(auto&i:st[x]){
st[y].insert(i);
}
}
void dfs(int x){
for(auto&nxt:way2[x]){
ans[nxt] += ans[x];
dfs(nxt);
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
nodeN = n;
vector<vector<int>> srt;
for(int i = 1; i <= n; ++i){
cin >> a[i];
srt.push_back({a[i], i});
}
for(int i = 0; i < m; ++i){
int x, y; cin >> x >> y;
way[x].push_back(y), way[y].push_back(x);
}
sort(srt.begin(), srt.end());
for(int i = 0; i < n; ++i){
int now = srt[i][1];
mesum[now] = a[now];
chk[now] = 1; pr[now] = now;
for(auto&nxt:way[now]){
if(chk[nxt]){
int npr = fd(nxt);
auto p = st[npr].lower_bound({a[now], now});
if(p != st[npr].end() && p->second == now){
st[npr].erase(p);
}
}
else{
st[now].insert({a[nxt], nxt});
}
}
for(auto&nxt:way[now]){
if(!chk[nxt]){
continue;
}
unite(now, nxt);
}
int u = fd(now);
if((int)st[u].size() && mesum[u] < st[u].begin()->first){
++nodeN;
pr[u] = pr[nodeN] = nodeN;
way2[nodeN].push_back(u);
ans[u] = 1;
}
}
for(int i = 1; i <= n; ++i){
if(fd(i) != fd(1)){
cout << string(n, '0') << '\n';
return 0;
}
}
dfs(fd(1));
for(int i = 1; i <= n; ++i){
cout << (!ans[i]);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
22 ms |
37904 KB |
Output is correct |
3 |
Correct |
21 ms |
37844 KB |
Output is correct |
4 |
Incorrect |
21 ms |
38232 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
37844 KB |
Output is correct |
2 |
Correct |
19 ms |
37816 KB |
Output is correct |
3 |
Incorrect |
203 ms |
76512 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
37888 KB |
Output is correct |
2 |
Incorrect |
336 ms |
80608 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
37844 KB |
Output is correct |
2 |
Incorrect |
339 ms |
80172 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
22 ms |
37904 KB |
Output is correct |
3 |
Correct |
21 ms |
37844 KB |
Output is correct |
4 |
Incorrect |
21 ms |
38232 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |