#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
struct dsu{
vector<int> p, sz;
vector<bool> out;
vector<vector<int>> all;
vector<ll> s;
int n;
dsu(int ns, vector<int>& x){
n = ns;
p.resize(n + 1);
sz.resize(n + 1);
s.resize(n + 1);
out.assign(n + 1, 1);
all.resize(n + 1);
for (int i = 1; i <= n; i++){
p[i] = i;
sz[i] = 1;
s[i] = x[i];
all[i] = {i};
}
}
int get(int v){
if (p[v] != v){
p[v] = get(p[v]);
}
return p[v];
}
void unite(int x, int y, int val){
x = get(x); y = get(y);
if (x == y) return;
if (s[x] < val){
for (int i: all[x]){
out[i] = 0;
}
}
if (sz[x] > sz[y]){
swap(x, y);
}
p[x] = y;
sz[y] += sz[x];
for (int i: all[x]) all[y].push_back(i);
s[y] += s[x];
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m; cin>>n>>m;
vector<int> x(n + 1), p = {0};
for (int i = 1; i <= n; i++){
cin>>x[i];
p.push_back(i);
}
auto cmp = [&](int i, int j){
return x[i] < x[j];
};
sort(p.begin(), p.end(), cmp);
vector<int> g[n + 1];
while (m--){
int a, b; cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
int i = 1;
dsu T(n, x);
while (i <= n){
int j = i;
while (j <= n && x[p[i]] == x[p[j]]){
j++;
}
for (int k = i; k < j; k++){
int v = p[k];
for (int u: g[v]){
if (x[u] <= x[v]){
T.unite(u, v, x[v]);
}
}
}
i = j;
}
for (int i = 1; i <= n; i++){
cout<<T.out[i];
}
cout<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
133 ms |
29048 KB |
Output is correct |
4 |
Correct |
127 ms |
31424 KB |
Output is correct |
5 |
Correct |
128 ms |
32716 KB |
Output is correct |
6 |
Correct |
156 ms |
38088 KB |
Output is correct |
7 |
Correct |
148 ms |
38196 KB |
Output is correct |
8 |
Correct |
155 ms |
34816 KB |
Output is correct |
9 |
Correct |
121 ms |
42016 KB |
Output is correct |
10 |
Correct |
106 ms |
32932 KB |
Output is correct |
11 |
Correct |
96 ms |
32828 KB |
Output is correct |
12 |
Correct |
143 ms |
33996 KB |
Output is correct |
13 |
Correct |
123 ms |
35076 KB |
Output is correct |
14 |
Correct |
110 ms |
34512 KB |
Output is correct |
15 |
Correct |
100 ms |
32976 KB |
Output is correct |
16 |
Correct |
82 ms |
31940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
167 ms |
35084 KB |
Output is correct |
3 |
Correct |
166 ms |
39724 KB |
Output is correct |
4 |
Correct |
147 ms |
36640 KB |
Output is correct |
5 |
Correct |
101 ms |
35484 KB |
Output is correct |
6 |
Correct |
177 ms |
39780 KB |
Output is correct |
7 |
Correct |
118 ms |
32980 KB |
Output is correct |
8 |
Correct |
143 ms |
33088 KB |
Output is correct |
9 |
Correct |
80 ms |
32088 KB |
Output is correct |
10 |
Correct |
143 ms |
35548 KB |
Output is correct |
11 |
Correct |
139 ms |
35536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
173 ms |
30800 KB |
Output is correct |
3 |
Correct |
193 ms |
31376 KB |
Output is correct |
4 |
Correct |
188 ms |
32572 KB |
Output is correct |
5 |
Correct |
168 ms |
31416 KB |
Output is correct |
6 |
Correct |
170 ms |
28904 KB |
Output is correct |
7 |
Correct |
118 ms |
29376 KB |
Output is correct |
8 |
Correct |
95 ms |
30424 KB |
Output is correct |
9 |
Correct |
78 ms |
16168 KB |
Output is correct |
10 |
Correct |
162 ms |
32480 KB |
Output is correct |
11 |
Correct |
140 ms |
32200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
133 ms |
29048 KB |
Output is correct |
18 |
Correct |
127 ms |
31424 KB |
Output is correct |
19 |
Correct |
128 ms |
32716 KB |
Output is correct |
20 |
Correct |
156 ms |
38088 KB |
Output is correct |
21 |
Correct |
148 ms |
38196 KB |
Output is correct |
22 |
Correct |
155 ms |
34816 KB |
Output is correct |
23 |
Correct |
121 ms |
42016 KB |
Output is correct |
24 |
Correct |
106 ms |
32932 KB |
Output is correct |
25 |
Correct |
96 ms |
32828 KB |
Output is correct |
26 |
Correct |
143 ms |
33996 KB |
Output is correct |
27 |
Correct |
123 ms |
35076 KB |
Output is correct |
28 |
Correct |
110 ms |
34512 KB |
Output is correct |
29 |
Correct |
100 ms |
32976 KB |
Output is correct |
30 |
Correct |
82 ms |
31940 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
167 ms |
35084 KB |
Output is correct |
33 |
Correct |
166 ms |
39724 KB |
Output is correct |
34 |
Correct |
147 ms |
36640 KB |
Output is correct |
35 |
Correct |
101 ms |
35484 KB |
Output is correct |
36 |
Correct |
177 ms |
39780 KB |
Output is correct |
37 |
Correct |
118 ms |
32980 KB |
Output is correct |
38 |
Correct |
143 ms |
33088 KB |
Output is correct |
39 |
Correct |
80 ms |
32088 KB |
Output is correct |
40 |
Correct |
143 ms |
35548 KB |
Output is correct |
41 |
Correct |
139 ms |
35536 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
173 ms |
30800 KB |
Output is correct |
44 |
Correct |
193 ms |
31376 KB |
Output is correct |
45 |
Correct |
188 ms |
32572 KB |
Output is correct |
46 |
Correct |
168 ms |
31416 KB |
Output is correct |
47 |
Correct |
170 ms |
28904 KB |
Output is correct |
48 |
Correct |
118 ms |
29376 KB |
Output is correct |
49 |
Correct |
95 ms |
30424 KB |
Output is correct |
50 |
Correct |
78 ms |
16168 KB |
Output is correct |
51 |
Correct |
162 ms |
32480 KB |
Output is correct |
52 |
Correct |
140 ms |
32200 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
468 KB |
Output is correct |
59 |
Correct |
2 ms |
860 KB |
Output is correct |
60 |
Correct |
1 ms |
604 KB |
Output is correct |
61 |
Correct |
1 ms |
604 KB |
Output is correct |
62 |
Correct |
1 ms |
776 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
604 KB |
Output is correct |
65 |
Correct |
1 ms |
724 KB |
Output is correct |
66 |
Correct |
1 ms |
604 KB |
Output is correct |
67 |
Correct |
115 ms |
33480 KB |
Output is correct |
68 |
Correct |
106 ms |
34456 KB |
Output is correct |
69 |
Correct |
129 ms |
36812 KB |
Output is correct |
70 |
Correct |
132 ms |
38080 KB |
Output is correct |
71 |
Correct |
166 ms |
38076 KB |
Output is correct |
72 |
Correct |
175 ms |
34800 KB |
Output is correct |
73 |
Correct |
113 ms |
42188 KB |
Output is correct |
74 |
Correct |
138 ms |
32756 KB |
Output is correct |
75 |
Correct |
92 ms |
32732 KB |
Output is correct |
76 |
Correct |
139 ms |
34004 KB |
Output is correct |
77 |
Correct |
123 ms |
34908 KB |
Output is correct |
78 |
Correct |
105 ms |
34580 KB |
Output is correct |
79 |
Correct |
98 ms |
32972 KB |
Output is correct |
80 |
Correct |
76 ms |
31944 KB |
Output is correct |
81 |
Correct |
172 ms |
39716 KB |
Output is correct |
82 |
Correct |
156 ms |
39628 KB |
Output is correct |
83 |
Correct |
118 ms |
36564 KB |
Output is correct |
84 |
Correct |
109 ms |
35540 KB |
Output is correct |
85 |
Correct |
179 ms |
39628 KB |
Output is correct |
86 |
Correct |
113 ms |
33068 KB |
Output is correct |
87 |
Correct |
125 ms |
33068 KB |
Output is correct |
88 |
Correct |
139 ms |
35368 KB |
Output is correct |
89 |
Correct |
123 ms |
35552 KB |
Output is correct |
90 |
Correct |
172 ms |
35748 KB |
Output is correct |
91 |
Correct |
155 ms |
35788 KB |
Output is correct |
92 |
Correct |
163 ms |
37068 KB |
Output is correct |
93 |
Correct |
144 ms |
35792 KB |
Output is correct |
94 |
Correct |
157 ms |
33020 KB |
Output is correct |
95 |
Correct |
94 ms |
33648 KB |
Output is correct |
96 |
Correct |
87 ms |
33992 KB |
Output is correct |
97 |
Correct |
90 ms |
18896 KB |
Output is correct |
98 |
Correct |
162 ms |
35156 KB |
Output is correct |
99 |
Correct |
128 ms |
35120 KB |
Output is correct |
100 |
Correct |
29 ms |
4696 KB |
Output is correct |
101 |
Correct |
194 ms |
36704 KB |
Output is correct |
102 |
Correct |
114 ms |
27596 KB |
Output is correct |
103 |
Correct |
140 ms |
28992 KB |
Output is correct |
104 |
Correct |
195 ms |
34292 KB |
Output is correct |