#include "bits/stdc++.h"
using namespace std;
#define int long long
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll read() { int x; cin >> x; return (ll)x; }
long long bm(long long b, long long p) {
if(p==0) return 1 % MOD;
long long r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
long long inv(long long b) {
return bm(b, MOD-2);
}
long long f[MAXN];
long long nCr(int n, int r) {
long long ans = f[n]; ans *= inv(f[r]); ans %= MOD;
ans *= inv(f[n-r]); ans %= MOD; return ans;
}
long long fib[MAXN], lucas[MAXN];
void precomp() {
for(int i=0; i<MAXN; i++) f[i] = (i == 0 ? 1 % MOD : (f[i-1] * i) % MOD);
lucas[0] = 2;
lucas[1] = 1;
for(int i=2; i<MAXN; i++) lucas[i] = (lucas[i-2] + lucas[i-1]) % MOD;
fib[0] = 0;
fib[1] = 1;
for(int i=2; i<MAXN; i++) fib[i] = (fib[i-2] + fib[i-1]) % MOD;
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void gay(int i) { cout << "Case #" << i << ": "; }
int csb(int l, int r, int k) { // count number of [l, r] such that i & 2^k > 0
if(l > r) return 0;
if(l == 0) {
int s = r / (1ll << (k+1)); // number of complete cycles
int t = r % (1ll << (k+1));
int ans = s * (1ll << k);
ans += (t >= (1ll << k) ? t - (1ll << k) + 1 : 0);
return ans;
}
else return csb(0, r, k) - csb(0, l - 1, k);
}
int lis(vector<int> a) {
int n = a.size();
int bucket[n+1];
for(int i=1; i<=n; i++) bucket[i] = 1e18;
int ans = 1;
for(int x: a) {
auto it = lower_bound(bucket + 1, bucket +n +1, x);
int d = distance(bucket, it);
ans = max(ans, d);
bucket[d] = min(bucket[d], x);
}
return ans;
}
struct disjoint_sets {
vector<int> dsu;
vector<int> sizes;
public:
void resize(int n) {
dsu.resize(n + 10);
sizes.resize(n + 10);
for(int i=0; i<n+10; i++) dsu[i] = i;
}
void set_size(int i, int x) {
sizes[i] = x;
}
int get_size(int i) {
return sizes[set_of(i)];
}
int set_of(int u) {
if(dsu[u] == u) return u;
return dsu[u] = set_of(dsu[u]);
}
void union_sets(int u, int v) {
int o = sizes[set_of(u)] + sizes[set_of(v)];
dsu[set_of(u)] = set_of(v);
sizes[set_of(u)] = o;
}
};
void solve(int tc) {
int n, m;
cin >> n >> m;
disjoint_sets dsu;
dsu.resize(n);
pair<int, int> s[n+1];
for(int i=1; i<=n; i++) {
cin >> s[i].first;
s[i].second = i;
dsu.set_size(i, s[i].first);
}
vector<int >adj[n+1];
for(int i=1; i<=m; i++) {
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
sort(s+1, s+n+1);
bool done[n+1], bad[n+1];
for(int i=1; i<=n; i++) done[i] = 0, bad[i] = 0;
set<int> indices[n+1];
int rep[n+1];
for(int i=1; i<=n; i++) {
rep[i] = i;
indices[i].insert(i);
}
for(int i=1; i<=n; i++) {
int node = s[i].second, val = s[i].first;
//cout << val << " " << node << " o\n";
for(int x: adj[node]) {
if(dsu.set_of(node) != dsu.set_of(x) && done[x]) {
//cout << "dsu size (" << x << ") = " << dsu.get_size(x) << ", val = " << val << "\n";
if(dsu.get_size(x) < val) {
for(int j: indices[rep[dsu.set_of(x)]]) {
bad[j] = 1;
}
}
int nw;
if(indices[rep[dsu.set_of(node)]].size() < indices[rep[dsu.set_of(x)]].size()) {
nw = rep[dsu.set_of(x)];
for(int y: indices[rep[dsu.set_of(node)]]) {
indices[rep[dsu.set_of(x)]].insert(y);
}
}
else {
nw = rep[dsu.set_of(node)];
for(int y: indices[rep[dsu.set_of(x)]]) {
indices[rep[dsu.set_of(node)]].insert(y);
}
}
dsu.union_sets(node, x);
rep[dsu.set_of(node)] = nw;
//cout << "union " << node << " " << x << "\n";
}
}
done[node] = 1;
}
for(int i=1; i<=n; i++) cout << (bad[i] ? 0 : 1);
cout << "\n";
}
/*
Set is bad if:
Sum(Set) < Min(Outgoing S)
If set bad, answer = 0 for all in set
Use KRT to update
4 3
5 7 3 5
1 2
2 3
3 4
*/
int32_t main() {
precomp();
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7252 KB |
Output is correct |
2 |
Correct |
9 ms |
7252 KB |
Output is correct |
3 |
Correct |
8 ms |
7372 KB |
Output is correct |
4 |
Correct |
9 ms |
7764 KB |
Output is correct |
5 |
Correct |
10 ms |
8020 KB |
Output is correct |
6 |
Correct |
9 ms |
7724 KB |
Output is correct |
7 |
Correct |
9 ms |
7764 KB |
Output is correct |
8 |
Correct |
9 ms |
7764 KB |
Output is correct |
9 |
Correct |
9 ms |
7764 KB |
Output is correct |
10 |
Correct |
10 ms |
8148 KB |
Output is correct |
11 |
Correct |
13 ms |
8016 KB |
Output is correct |
12 |
Correct |
11 ms |
8216 KB |
Output is correct |
13 |
Correct |
10 ms |
7764 KB |
Output is correct |
14 |
Correct |
9 ms |
8020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7376 KB |
Output is correct |
2 |
Correct |
8 ms |
7252 KB |
Output is correct |
3 |
Correct |
207 ms |
65328 KB |
Output is correct |
4 |
Correct |
214 ms |
59956 KB |
Output is correct |
5 |
Correct |
403 ms |
89388 KB |
Output is correct |
6 |
Correct |
406 ms |
94408 KB |
Output is correct |
7 |
Correct |
414 ms |
93284 KB |
Output is correct |
8 |
Correct |
216 ms |
60368 KB |
Output is correct |
9 |
Correct |
407 ms |
128804 KB |
Output is correct |
10 |
Correct |
281 ms |
59980 KB |
Output is correct |
11 |
Correct |
199 ms |
59796 KB |
Output is correct |
12 |
Correct |
342 ms |
67128 KB |
Output is correct |
13 |
Correct |
194 ms |
57808 KB |
Output is correct |
14 |
Correct |
209 ms |
58816 KB |
Output is correct |
15 |
Correct |
194 ms |
59308 KB |
Output is correct |
16 |
Correct |
158 ms |
58220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7252 KB |
Output is correct |
2 |
Correct |
482 ms |
106308 KB |
Output is correct |
3 |
Correct |
473 ms |
106216 KB |
Output is correct |
4 |
Correct |
215 ms |
59340 KB |
Output is correct |
5 |
Correct |
227 ms |
60740 KB |
Output is correct |
6 |
Correct |
499 ms |
105264 KB |
Output is correct |
7 |
Correct |
278 ms |
59452 KB |
Output is correct |
8 |
Correct |
271 ms |
59392 KB |
Output is correct |
9 |
Correct |
155 ms |
58096 KB |
Output is correct |
10 |
Correct |
224 ms |
61624 KB |
Output is correct |
11 |
Correct |
264 ms |
69824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7252 KB |
Output is correct |
2 |
Correct |
566 ms |
78988 KB |
Output is correct |
3 |
Correct |
558 ms |
84188 KB |
Output is correct |
4 |
Correct |
518 ms |
91540 KB |
Output is correct |
5 |
Correct |
442 ms |
85664 KB |
Output is correct |
6 |
Correct |
393 ms |
70620 KB |
Output is correct |
7 |
Correct |
213 ms |
60836 KB |
Output is correct |
8 |
Correct |
168 ms |
59788 KB |
Output is correct |
9 |
Correct |
187 ms |
41056 KB |
Output is correct |
10 |
Correct |
463 ms |
89940 KB |
Output is correct |
11 |
Correct |
238 ms |
67780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7252 KB |
Output is correct |
2 |
Correct |
9 ms |
7252 KB |
Output is correct |
3 |
Correct |
8 ms |
7372 KB |
Output is correct |
4 |
Correct |
9 ms |
7764 KB |
Output is correct |
5 |
Correct |
10 ms |
8020 KB |
Output is correct |
6 |
Correct |
9 ms |
7724 KB |
Output is correct |
7 |
Correct |
9 ms |
7764 KB |
Output is correct |
8 |
Correct |
9 ms |
7764 KB |
Output is correct |
9 |
Correct |
9 ms |
7764 KB |
Output is correct |
10 |
Correct |
10 ms |
8148 KB |
Output is correct |
11 |
Correct |
13 ms |
8016 KB |
Output is correct |
12 |
Correct |
11 ms |
8216 KB |
Output is correct |
13 |
Correct |
10 ms |
7764 KB |
Output is correct |
14 |
Correct |
9 ms |
8020 KB |
Output is correct |
15 |
Correct |
8 ms |
7376 KB |
Output is correct |
16 |
Correct |
8 ms |
7252 KB |
Output is correct |
17 |
Correct |
207 ms |
65328 KB |
Output is correct |
18 |
Correct |
214 ms |
59956 KB |
Output is correct |
19 |
Correct |
403 ms |
89388 KB |
Output is correct |
20 |
Correct |
406 ms |
94408 KB |
Output is correct |
21 |
Correct |
414 ms |
93284 KB |
Output is correct |
22 |
Correct |
216 ms |
60368 KB |
Output is correct |
23 |
Correct |
407 ms |
128804 KB |
Output is correct |
24 |
Correct |
281 ms |
59980 KB |
Output is correct |
25 |
Correct |
199 ms |
59796 KB |
Output is correct |
26 |
Correct |
342 ms |
67128 KB |
Output is correct |
27 |
Correct |
194 ms |
57808 KB |
Output is correct |
28 |
Correct |
209 ms |
58816 KB |
Output is correct |
29 |
Correct |
194 ms |
59308 KB |
Output is correct |
30 |
Correct |
158 ms |
58220 KB |
Output is correct |
31 |
Correct |
8 ms |
7252 KB |
Output is correct |
32 |
Correct |
482 ms |
106308 KB |
Output is correct |
33 |
Correct |
473 ms |
106216 KB |
Output is correct |
34 |
Correct |
215 ms |
59340 KB |
Output is correct |
35 |
Correct |
227 ms |
60740 KB |
Output is correct |
36 |
Correct |
499 ms |
105264 KB |
Output is correct |
37 |
Correct |
278 ms |
59452 KB |
Output is correct |
38 |
Correct |
271 ms |
59392 KB |
Output is correct |
39 |
Correct |
155 ms |
58096 KB |
Output is correct |
40 |
Correct |
224 ms |
61624 KB |
Output is correct |
41 |
Correct |
264 ms |
69824 KB |
Output is correct |
42 |
Correct |
9 ms |
7252 KB |
Output is correct |
43 |
Correct |
566 ms |
78988 KB |
Output is correct |
44 |
Correct |
558 ms |
84188 KB |
Output is correct |
45 |
Correct |
518 ms |
91540 KB |
Output is correct |
46 |
Correct |
442 ms |
85664 KB |
Output is correct |
47 |
Correct |
393 ms |
70620 KB |
Output is correct |
48 |
Correct |
213 ms |
60836 KB |
Output is correct |
49 |
Correct |
168 ms |
59788 KB |
Output is correct |
50 |
Correct |
187 ms |
41056 KB |
Output is correct |
51 |
Correct |
463 ms |
89940 KB |
Output is correct |
52 |
Correct |
238 ms |
67780 KB |
Output is correct |
53 |
Correct |
8 ms |
7252 KB |
Output is correct |
54 |
Correct |
8 ms |
7356 KB |
Output is correct |
55 |
Correct |
8 ms |
7252 KB |
Output is correct |
56 |
Correct |
10 ms |
7844 KB |
Output is correct |
57 |
Correct |
10 ms |
7988 KB |
Output is correct |
58 |
Correct |
9 ms |
7724 KB |
Output is correct |
59 |
Correct |
9 ms |
7764 KB |
Output is correct |
60 |
Correct |
9 ms |
7740 KB |
Output is correct |
61 |
Correct |
9 ms |
7764 KB |
Output is correct |
62 |
Correct |
11 ms |
8088 KB |
Output is correct |
63 |
Correct |
10 ms |
8020 KB |
Output is correct |
64 |
Correct |
10 ms |
8148 KB |
Output is correct |
65 |
Correct |
9 ms |
7768 KB |
Output is correct |
66 |
Correct |
10 ms |
7972 KB |
Output is correct |
67 |
Correct |
205 ms |
65320 KB |
Output is correct |
68 |
Correct |
235 ms |
59936 KB |
Output is correct |
69 |
Correct |
404 ms |
89344 KB |
Output is correct |
70 |
Correct |
413 ms |
94408 KB |
Output is correct |
71 |
Correct |
434 ms |
93256 KB |
Output is correct |
72 |
Correct |
223 ms |
60328 KB |
Output is correct |
73 |
Correct |
408 ms |
128796 KB |
Output is correct |
74 |
Correct |
295 ms |
59948 KB |
Output is correct |
75 |
Correct |
194 ms |
59856 KB |
Output is correct |
76 |
Correct |
370 ms |
67196 KB |
Output is correct |
77 |
Correct |
202 ms |
57784 KB |
Output is correct |
78 |
Correct |
205 ms |
59032 KB |
Output is correct |
79 |
Correct |
194 ms |
59312 KB |
Output is correct |
80 |
Correct |
159 ms |
58060 KB |
Output is correct |
81 |
Correct |
462 ms |
106376 KB |
Output is correct |
82 |
Correct |
455 ms |
106076 KB |
Output is correct |
83 |
Correct |
224 ms |
59424 KB |
Output is correct |
84 |
Correct |
203 ms |
60732 KB |
Output is correct |
85 |
Correct |
465 ms |
105356 KB |
Output is correct |
86 |
Correct |
236 ms |
59272 KB |
Output is correct |
87 |
Correct |
229 ms |
59320 KB |
Output is correct |
88 |
Correct |
194 ms |
61900 KB |
Output is correct |
89 |
Correct |
230 ms |
69832 KB |
Output is correct |
90 |
Correct |
449 ms |
78840 KB |
Output is correct |
91 |
Correct |
461 ms |
84100 KB |
Output is correct |
92 |
Correct |
542 ms |
91520 KB |
Output is correct |
93 |
Correct |
459 ms |
85708 KB |
Output is correct |
94 |
Correct |
367 ms |
70712 KB |
Output is correct |
95 |
Correct |
238 ms |
60824 KB |
Output is correct |
96 |
Correct |
161 ms |
59708 KB |
Output is correct |
97 |
Correct |
213 ms |
41124 KB |
Output is correct |
98 |
Correct |
461 ms |
89944 KB |
Output is correct |
99 |
Correct |
235 ms |
67884 KB |
Output is correct |
100 |
Correct |
48 ms |
14196 KB |
Output is correct |
101 |
Correct |
502 ms |
89164 KB |
Output is correct |
102 |
Correct |
270 ms |
56032 KB |
Output is correct |
103 |
Correct |
360 ms |
59552 KB |
Output is correct |
104 |
Correct |
481 ms |
74344 KB |
Output is correct |