#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
using namespace std;
const int NMAX = 200001;
class DSU{
public:
int parent[NMAX], cnt[NMAX];
long long suma[NMAX];
vector <int> comp[NMAX];
int root(int x){
if(x == parent[x])
return x;
return parent[x] = root(parent[x]);
}
void merge(int a, int b){
a = root(a);
b = root(b);
if(a == b)
return;
if(cnt[a] < cnt[b])
swap(a, b);
cnt[a] += cnt[b];
parent[b] = a;
suma[a] += suma[b];
for(auto x : comp[b])
comp[a].push_back(x);
comp[b].clear();
}
}dsu;
vector <int> v[NMAX];
int rez[NMAX];
int p[NMAX];
int idx[NMAX];
bool cmp(int a, int b){
return p[a] < p[b];
}
int main()
{
ifstream cin(".in");
ofstream cout(".out");
int n, m, i;
cin >> n >> m;
for(i = 1; i <= n; i++){
cin >> p[i];
rez[i] = 1;
dsu.parent[i] = i;
dsu.cnt[i] = 1;
dsu.suma[i] = p[i];
dsu.comp[i].clear();
dsu.comp[i].push_back(i);
idx[i] = i;
}
for(i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
sort(idx + 1, idx + n + 1, cmp);
for(i = 1; i <= n; i++){
int x = idx[i];
for(auto vecin : v[x]){
if(p[vecin] < p[x]){
int rV = dsu.root(vecin);
if(dsu.suma[rV] < p[x]){
for(auto y : dsu.comp[rV]){
rez[y] = 0;
}
dsu.comp[rV].clear();
}
}
}
for(auto vecin : v[x]){
if(p[vecin] <= p[x]){
dsu.merge(x, vecin);
}
}
}
set <int> st;
for(i = 1; i <= n; i++)
st.insert(dsu.root(i));
for(i = 1; i <= n; i++){
cout << rez[i] * (st.size() == 1);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |