#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << x << "\n"
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
const int inf = 1e9;
const ll LLinf = 1e16;
int siz[N], rep[N];
ll sum[N];
bool lose[N];
vector<int> child[N];
int id(int x){
while(rep[x]!=x)x=rep[x];
return x;
}
bool same(int a, int b){
return id(a) == id(b);
}
void connect(int a, int b){
a = id(a); b = id(b);
if(siz[a] > siz[b])swap(a, b);
siz[b] += siz[a];
sum[b] += sum[a];
rep[a] = b;
child[b].push_back(a);
}
void init_uf(){
for(int i = 1; i < N; ++i){
siz[i] = 1;
rep[i] = i;
}
}
ll pop[N];
vector<int> g[N];
bool res[N], hand[N];
void update_res(int cur, bool f){
f = f || lose[cur];
res[cur] = f;
hand[cur] = 1;
for(int nex : child[cur]){
update_res(nex, f);
}
}
int main(){
// if cannot get to any new ones:
// fail for this and its children
//
// uf: size, sum, rep
// kusee jos kaikki naapurit suurempii
init_uf();
int n, m;
cin >> n >> m;
vector<pair<ll, int>> v;
for(int i = 1; i <= n; ++i){
ll x; cin >> x;
pop[i] = sum[i] = x;
v.push_back({x, i});
}
sort(all(v));
while(m--){
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for(auto [x, node] : v){
vector<int> con;
for(auto nex : g[node]){
if(same(node, nex))continue;
nex = id(nex);
if(pop[node] > sum[nex]){
lose[nex] = 1;
}else if(pop[node] >= pop[nex]){
con.push_back(nex);
}
}
for(int nex : con)if(!same(node, nex))connect(node, nex);
}
for(int i = 1; i <= n; ++i){
// cout << i << " " << id(i) << "\n";
// cout << lose[i] << "\n";
if(hand[id(i)])continue;
// cout << "yea\n";
update_res(id(i), 0);
}
for(int i = 1; i <= n; ++i){
cout << !res[i];
}
cout << "\n";
//
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11220 KB |
Output is correct |
2 |
Correct |
6 ms |
11252 KB |
Output is correct |
3 |
Correct |
6 ms |
11280 KB |
Output is correct |
4 |
Incorrect |
9 ms |
11420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
11280 KB |
Output is correct |
2 |
Correct |
5 ms |
11200 KB |
Output is correct |
3 |
Incorrect |
289 ms |
29912 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
11224 KB |
Output is correct |
2 |
Incorrect |
329 ms |
28816 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11276 KB |
Output is correct |
2 |
Incorrect |
330 ms |
29488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11220 KB |
Output is correct |
2 |
Correct |
6 ms |
11252 KB |
Output is correct |
3 |
Correct |
6 ms |
11280 KB |
Output is correct |
4 |
Incorrect |
9 ms |
11420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |