#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#define pii pair <int, int>
using namespace std;
//ifstream fin("input.in");
//ofstream fout("output.out");
#define fin cin
#define fout cout
const int NMAX = 2e5;
int v[NMAX + 1];
vector <int> adj[NMAX + 1];
int par[NMAX + 1];
int sum[NMAX + 1];
bool bad[NMAX + 1];
int Find(int x){
if(x == par[x]){
return x;
}
par[x] = Find(par[x]);
bad[x] |= bad[par[x]];
return par[x];
}
void Join(int x, int y){
x = par[x];
y = par[y];
par[x] = y;
sum[y] += sum[x];
}
bool ins[NMAX + 1];
void Insert(int x){
ins[x] = true;
for(int vec : adj[x]){
if(ins[vec]){
Join(vec, x);
}
}
}
vector <int> inds[NMAX + 1];
int main(){
int n, m;
cin >> n >> m;
priority_queue <pii, vector <pii>, greater <pii>> pq;
vector <int> vals;
for(int i = 1; i <= n; i++){
cin >> v[i];
par[i] = i;
sum[i] = v[i];
vals.push_back(v[i]);
}
for(int i = 1; i <= m; i++){
int a, b;
fin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
sort(vals.begin(), vals.end());
vals.erase(unique(vals.begin(), vals.end()), vals.end());
map <int, int> norm;
for(int i = 0; i < (int)vals.size(); i++){
norm[vals[i]] = i;
}
for(int i = 1; i <= n; i++){
inds[norm[v[i]]].push_back(i);
}
for(int val = 0; val < (int)vals.size(); val++){
for(int ind : inds[val]){
Insert(ind);
}
if(val + 1 < (int)vals.size()){
for(int ind : inds[val]){
if(sum[Find(ind)] < vals[val + 1]){
bad[Find(ind)] = true;
}
}
}
}
for(int i = 1; i <= n; i++){
Find(i);
cout << !bad[i];
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11608 KB |
Output is correct |
2 |
Correct |
2 ms |
11612 KB |
Output is correct |
3 |
Correct |
2 ms |
11612 KB |
Output is correct |
4 |
Incorrect |
4 ms |
11868 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11612 KB |
Output is correct |
2 |
Correct |
2 ms |
11612 KB |
Output is correct |
3 |
Incorrect |
255 ms |
35356 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11612 KB |
Output is correct |
2 |
Incorrect |
356 ms |
35240 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11612 KB |
Output is correct |
2 |
Incorrect |
219 ms |
20936 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11608 KB |
Output is correct |
2 |
Correct |
2 ms |
11612 KB |
Output is correct |
3 |
Correct |
2 ms |
11612 KB |
Output is correct |
4 |
Incorrect |
4 ms |
11868 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |