#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 2e5 + 100;
vector <int> save[N];
int sz[N], p[N], ans[N];
ll sum[N], s[N];
int get(int a) {
if (p[a] == 0)
return a;
return get(p[a]);
}
void unite(int a, int b) {
a = get(a);
b = get(b);
if (a == b)
return;
if (sz[a] > sz[b]) {
swap(a, b);
}
for (auto x : save[b])
save[a].pb(x);
sz[a] += sz[b];
sum[a] += sum[b];
p[b] = a;
}
vector <int> ed[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
fill(sz, sz + 1 + n, 1);
vector <pair <ll, ll>> lst;
for (int i = 1; i <= n; i++) {
cin >> s[i];
sum[i] = s[i];
save[i].pb(i);
lst.pb({s[i], i});
}
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
ed[a].pb(b);
ed[b].pb(a);
}
sort(all(lst));
for (auto e : lst) {
int i = e.s;
for (auto x : ed[i]) {
if (s[x] > s[i])
continue;
int c = get(x);
if (sum[c] < s[i]) {
for (auto t : save[c]) {
ans[t] = 1;
}
save[c].clear();
}
unite(c, i);
}
}
for (int i = 1; i <= n; i++)
cout << !ans[i];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
15196 KB |
Output is correct |
2 |
Correct |
3 ms |
15196 KB |
Output is correct |
3 |
Correct |
3 ms |
13260 KB |
Output is correct |
4 |
Correct |
6 ms |
17756 KB |
Output is correct |
5 |
Correct |
6 ms |
15964 KB |
Output is correct |
6 |
Correct |
11 ms |
18784 KB |
Output is correct |
7 |
Correct |
6 ms |
17500 KB |
Output is correct |
8 |
Correct |
8 ms |
17244 KB |
Output is correct |
9 |
Correct |
12 ms |
20572 KB |
Output is correct |
10 |
Correct |
5 ms |
15536 KB |
Output is correct |
11 |
Correct |
5 ms |
15588 KB |
Output is correct |
12 |
Correct |
4 ms |
15452 KB |
Output is correct |
13 |
Correct |
15 ms |
25592 KB |
Output is correct |
14 |
Correct |
4 ms |
15580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
15196 KB |
Output is correct |
2 |
Correct |
3 ms |
13288 KB |
Output is correct |
3 |
Runtime error |
531 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13148 KB |
Output is correct |
2 |
Correct |
223 ms |
50920 KB |
Output is correct |
3 |
Correct |
220 ms |
51512 KB |
Output is correct |
4 |
Runtime error |
455 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Runtime error |
634 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
15196 KB |
Output is correct |
2 |
Correct |
3 ms |
15196 KB |
Output is correct |
3 |
Correct |
3 ms |
13260 KB |
Output is correct |
4 |
Correct |
6 ms |
17756 KB |
Output is correct |
5 |
Correct |
6 ms |
15964 KB |
Output is correct |
6 |
Correct |
11 ms |
18784 KB |
Output is correct |
7 |
Correct |
6 ms |
17500 KB |
Output is correct |
8 |
Correct |
8 ms |
17244 KB |
Output is correct |
9 |
Correct |
12 ms |
20572 KB |
Output is correct |
10 |
Correct |
5 ms |
15536 KB |
Output is correct |
11 |
Correct |
5 ms |
15588 KB |
Output is correct |
12 |
Correct |
4 ms |
15452 KB |
Output is correct |
13 |
Correct |
15 ms |
25592 KB |
Output is correct |
14 |
Correct |
4 ms |
15580 KB |
Output is correct |
15 |
Correct |
3 ms |
15196 KB |
Output is correct |
16 |
Correct |
3 ms |
13288 KB |
Output is correct |
17 |
Runtime error |
531 ms |
524288 KB |
Execution killed with signal 9 |
18 |
Halted |
0 ms |
0 KB |
- |