#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> nums;
vector<bool> ans;
vector<pair<int, pair<int, int>>> pairs;
struct dsu {
vector<ll> par, siz;
dsu(int n) {
par.resize(n);
siz.resize(n);
for(int i = 0; i < n; i++) {
par[i] = i;
siz[i] = nums[i];
}
}
int get(int x) {
if(x == par[x]) return x;
if(ans[par[x]] == 0) ans[x] = 0;
get(par[x]);
if(ans[par[x]] == 0) ans[x] = 0;
return par[x] = get(par[x]);
}
ll getsiz(int x) {
return siz[get(x)];
}
bool unite(int x, int y) {
x = get(x); y = get(y);
if(x == y) return false;
if(siz[x] > siz[y]) swap(x, y);
par[x] = y;
siz[y] += siz[x];
return true;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
nums.resize(n);
ans.resize(n, 1);
pairs.resize(m);
for(int i = 0; i < n; i++) {
cin >> nums[i];
}
dsu uf(n);
for(int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--; y--;
pairs.push_back({max(nums[x], nums[y]), {x, y}});
}
sort(pairs.begin(), pairs.end());
for(auto p : pairs) {
int x, y;
tie(x, y) = p.second;
if(uf.getsiz(x) < nums[y]) ans[uf.get(x)] = 0;
if(uf.getsiz(y) < nums[x]) ans[uf.get(y)] = 0;
uf.unite(x, y);
}
for(int i = 0; i < n; i++) {
uf.get(i);
cout << ans[i];
}
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
111 ms |
9120 KB |
Output is correct |
4 |
Correct |
101 ms |
9048 KB |
Output is correct |
5 |
Correct |
94 ms |
8816 KB |
Output is correct |
6 |
Correct |
104 ms |
9032 KB |
Output is correct |
7 |
Correct |
101 ms |
9092 KB |
Output is correct |
8 |
Correct |
102 ms |
9140 KB |
Output is correct |
9 |
Correct |
103 ms |
9200 KB |
Output is correct |
10 |
Correct |
91 ms |
9088 KB |
Output is correct |
11 |
Correct |
86 ms |
9136 KB |
Output is correct |
12 |
Correct |
93 ms |
9108 KB |
Output is correct |
13 |
Correct |
96 ms |
9052 KB |
Output is correct |
14 |
Correct |
89 ms |
9160 KB |
Output is correct |
15 |
Correct |
92 ms |
9040 KB |
Output is correct |
16 |
Correct |
93 ms |
8996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
104 ms |
9012 KB |
Output is correct |
3 |
Correct |
104 ms |
9156 KB |
Output is correct |
4 |
Correct |
96 ms |
9140 KB |
Output is correct |
5 |
Correct |
87 ms |
9088 KB |
Output is correct |
6 |
Correct |
109 ms |
9204 KB |
Output is correct |
7 |
Correct |
93 ms |
9036 KB |
Output is correct |
8 |
Correct |
98 ms |
9188 KB |
Output is correct |
9 |
Correct |
85 ms |
9060 KB |
Output is correct |
10 |
Correct |
96 ms |
9080 KB |
Output is correct |
11 |
Correct |
95 ms |
9064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
109 ms |
9052 KB |
Output is correct |
3 |
Correct |
125 ms |
9100 KB |
Output is correct |
4 |
Correct |
116 ms |
9092 KB |
Output is correct |
5 |
Correct |
100 ms |
9076 KB |
Output is correct |
6 |
Correct |
122 ms |
8872 KB |
Output is correct |
7 |
Correct |
99 ms |
9208 KB |
Output is correct |
8 |
Correct |
78 ms |
9036 KB |
Output is correct |
9 |
Correct |
79 ms |
6996 KB |
Output is correct |
10 |
Correct |
94 ms |
9068 KB |
Output is correct |
11 |
Correct |
101 ms |
9100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
111 ms |
9120 KB |
Output is correct |
18 |
Correct |
101 ms |
9048 KB |
Output is correct |
19 |
Correct |
94 ms |
8816 KB |
Output is correct |
20 |
Correct |
104 ms |
9032 KB |
Output is correct |
21 |
Correct |
101 ms |
9092 KB |
Output is correct |
22 |
Correct |
102 ms |
9140 KB |
Output is correct |
23 |
Correct |
103 ms |
9200 KB |
Output is correct |
24 |
Correct |
91 ms |
9088 KB |
Output is correct |
25 |
Correct |
86 ms |
9136 KB |
Output is correct |
26 |
Correct |
93 ms |
9108 KB |
Output is correct |
27 |
Correct |
96 ms |
9052 KB |
Output is correct |
28 |
Correct |
89 ms |
9160 KB |
Output is correct |
29 |
Correct |
92 ms |
9040 KB |
Output is correct |
30 |
Correct |
93 ms |
8996 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
104 ms |
9012 KB |
Output is correct |
33 |
Correct |
104 ms |
9156 KB |
Output is correct |
34 |
Correct |
96 ms |
9140 KB |
Output is correct |
35 |
Correct |
87 ms |
9088 KB |
Output is correct |
36 |
Correct |
109 ms |
9204 KB |
Output is correct |
37 |
Correct |
93 ms |
9036 KB |
Output is correct |
38 |
Correct |
98 ms |
9188 KB |
Output is correct |
39 |
Correct |
85 ms |
9060 KB |
Output is correct |
40 |
Correct |
96 ms |
9080 KB |
Output is correct |
41 |
Correct |
95 ms |
9064 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
109 ms |
9052 KB |
Output is correct |
44 |
Correct |
125 ms |
9100 KB |
Output is correct |
45 |
Correct |
116 ms |
9092 KB |
Output is correct |
46 |
Correct |
100 ms |
9076 KB |
Output is correct |
47 |
Correct |
122 ms |
8872 KB |
Output is correct |
48 |
Correct |
99 ms |
9208 KB |
Output is correct |
49 |
Correct |
78 ms |
9036 KB |
Output is correct |
50 |
Correct |
79 ms |
6996 KB |
Output is correct |
51 |
Correct |
94 ms |
9068 KB |
Output is correct |
52 |
Correct |
101 ms |
9100 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
1 ms |
340 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
99 ms |
9088 KB |
Output is correct |
68 |
Correct |
86 ms |
9100 KB |
Output is correct |
69 |
Correct |
115 ms |
8808 KB |
Output is correct |
70 |
Correct |
102 ms |
9068 KB |
Output is correct |
71 |
Correct |
96 ms |
9080 KB |
Output is correct |
72 |
Correct |
99 ms |
9128 KB |
Output is correct |
73 |
Correct |
97 ms |
9108 KB |
Output is correct |
74 |
Correct |
101 ms |
9068 KB |
Output is correct |
75 |
Correct |
87 ms |
9112 KB |
Output is correct |
76 |
Correct |
90 ms |
9208 KB |
Output is correct |
77 |
Correct |
88 ms |
9096 KB |
Output is correct |
78 |
Correct |
86 ms |
9096 KB |
Output is correct |
79 |
Correct |
89 ms |
9148 KB |
Output is correct |
80 |
Correct |
87 ms |
9040 KB |
Output is correct |
81 |
Correct |
124 ms |
9120 KB |
Output is correct |
82 |
Correct |
101 ms |
9076 KB |
Output is correct |
83 |
Correct |
93 ms |
9072 KB |
Output is correct |
84 |
Correct |
84 ms |
9148 KB |
Output is correct |
85 |
Correct |
98 ms |
9120 KB |
Output is correct |
86 |
Correct |
88 ms |
9096 KB |
Output is correct |
87 |
Correct |
96 ms |
9076 KB |
Output is correct |
88 |
Correct |
93 ms |
9204 KB |
Output is correct |
89 |
Correct |
91 ms |
9084 KB |
Output is correct |
90 |
Correct |
107 ms |
9068 KB |
Output is correct |
91 |
Correct |
125 ms |
9040 KB |
Output is correct |
92 |
Correct |
104 ms |
9044 KB |
Output is correct |
93 |
Correct |
111 ms |
9064 KB |
Output is correct |
94 |
Correct |
103 ms |
8776 KB |
Output is correct |
95 |
Correct |
92 ms |
9124 KB |
Output is correct |
96 |
Correct |
79 ms |
9224 KB |
Output is correct |
97 |
Correct |
85 ms |
6996 KB |
Output is correct |
98 |
Correct |
108 ms |
9164 KB |
Output is correct |
99 |
Correct |
112 ms |
9028 KB |
Output is correct |
100 |
Correct |
62 ms |
5036 KB |
Output is correct |
101 |
Correct |
105 ms |
9148 KB |
Output is correct |
102 |
Correct |
92 ms |
8224 KB |
Output is correct |
103 |
Correct |
109 ms |
8364 KB |
Output is correct |
104 |
Correct |
104 ms |
9052 KB |
Output is correct |