#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){
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);
}
mesum[y] += mesum[x];
for(auto&i:st[x]){
auto p = st[y].lower_bound(i);
if(p != st[y].end() && *p == i){
}
else{
st[y].insert(i);
}
}
++nodeN; pr[nodeN] = nodeN;
if((int)st[y].size() && mesum[y] < st[y].begin()->first){
ans[nodeN] = 1;
}
pr[x] = pr[y] = nodeN, mesum[nodeN] = mesum[y];
swap(st[y], st[nodeN]);
way2[nodeN].push_back(x), way2[nodeN].push_back(y);
}
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);
}
if(a[now] == mesum[fd(now)]){
if((int)st[now].size() && mesum[now] < st[now].begin()->first){
ans[now] = 1;
}
}
}
dfs(nodeN);
for(int i = 1; i <= n; ++i){
if(nodeN != n * 2 - 1) ans[i] = 1;
cout << (!ans[i]);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
37844 KB |
Output is correct |
2 |
Correct |
23 ms |
37840 KB |
Output is correct |
3 |
Correct |
19 ms |
37896 KB |
Output is correct |
4 |
Incorrect |
22 ms |
38420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
37904 KB |
Output is correct |
2 |
Correct |
20 ms |
37844 KB |
Output is correct |
3 |
Correct |
228 ms |
77620 KB |
Output is correct |
4 |
Correct |
234 ms |
90096 KB |
Output is correct |
5 |
Incorrect |
293 ms |
73892 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37872 KB |
Output is correct |
2 |
Incorrect |
461 ms |
82312 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
37844 KB |
Output is correct |
2 |
Incorrect |
484 ms |
83276 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
37844 KB |
Output is correct |
2 |
Correct |
23 ms |
37840 KB |
Output is correct |
3 |
Correct |
19 ms |
37896 KB |
Output is correct |
4 |
Incorrect |
22 ms |
38420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |