#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define si second
#define ar array
#define pb push_back
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
typedef vector<int> vi;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int N = 200010;
int n, m;
int s[N], p[N], vis[N], bad[N];
ll val[N];
vector<int> g[N];
vector<int> st[N];
int par(int x) {return p[x];}
bool same(int x, int y) {return par(x) == par(y);}
void merge(int x, int y) {
x = par(x), y = par(y);
if (st[x].size() < st[y].size()) swap(x, y);
if (x == y) return;
val[x] += val[y];
while (st[y].size()) {
int v = st[y].back();
st[y].pop_back();
p[v] = x;
st[x].pb(v);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin.exceptions(ios::badbit|ios::failbit);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> s[i];
val[i] = s[i];
p[i] = i;
st[i] = vector<int>(1, i);
}
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b;
--a, --b;
g[a].pb(b);
g[b].pb(a);
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int x, int y) {
return s[x] < s[y];
});
for (auto i: order) {
vis[i] = 1;
sort(g[i].begin(), g[i].end(), [&](int x, int y) {
return s[x] < s[y];
});
for (auto j: g[i]) {
if (same(i, j)) continue;
if (vis[j]) {
if (val[par(i)] > val[par(j)]) {
for (auto v: st[par(j)]) {
bad[v] = 1;
}
}
merge(i, j);
}
if (val[par(i)] >= val[par(j)]) {
merge(i, j);
}
}
}
for (int i = 0; i < n; ++i) {
cout << (bad[i] ? 0 : 1);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Incorrect |
5 ms |
12888 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Incorrect |
99 ms |
29208 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Incorrect |
195 ms |
35172 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Incorrect |
188 ms |
30824 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Incorrect |
5 ms |
12888 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |