#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 2;
int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<ll> s(n), sum(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
sum[i] = s[i];
}
vector<int> a(m), b(m);
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i];
a[i] -= 1;
b[i] -= 1;
if (s[a[i]] > s[b[i]]) swap(a[i], b[i]);
}
vector<int> order(m);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&] (int i, int j) {
return s[b[i]] < s[b[j]];
});
vector<int> p(n);
iota(p.begin(), p.end(), 0);
function<int(int)> Find = [&] (int x) {
if (x == p[x]) return x;
return p[x] = Find(p[x]);
};
vector<vector<int>> g(n);
function<void(int, int)> Unite = [&] (int u, int v) {
u = Find(u);
v = Find(v);
p[u] = v;
sum[v] += sum[u];
g[u].push_back(v);
};
vector<bool> can(n, 1);
for (int i : order) {
int x = Find(a[i]);
int y = Find(b[i]);
if (x == y) continue;
if (sum[x] < s[y]) can[x] = 0;
Unite(x, y);
}
vector<bool> was(n);
function<int(int)> Dfs = [&] (int s) {
if (was[s]) return can[s];
was[s] = 1;
for (int u : g[s]) {
if (Dfs(u) == 0) can[s] = 0;
}
return can[s];
};
for (int i = 0; i < n; i++) {
if (!was[i]) Dfs(i);
}
for (int i = 0; i < n; i++) cout << can[i];
cout << en;
return 0;
}
# |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 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 |
115 ms |
17728 KB |
Output is correct |
4 |
Correct |
126 ms |
17696 KB |
Output is correct |
5 |
Correct |
163 ms |
17144 KB |
Output is correct |
6 |
Correct |
139 ms |
17684 KB |
Output is correct |
7 |
Correct |
175 ms |
17828 KB |
Output is correct |
8 |
Correct |
149 ms |
17708 KB |
Output is correct |
9 |
Correct |
114 ms |
17688 KB |
Output is correct |
10 |
Correct |
122 ms |
17708 KB |
Output is correct |
11 |
Correct |
138 ms |
25500 KB |
Output is correct |
12 |
Correct |
161 ms |
17740 KB |
Output is correct |
13 |
Correct |
125 ms |
17744 KB |
Output is correct |
14 |
Correct |
169 ms |
17748 KB |
Output is correct |
15 |
Correct |
106 ms |
17732 KB |
Output is correct |
16 |
Correct |
75 ms |
17612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
182 ms |
17612 KB |
Output is correct |
3 |
Correct |
179 ms |
17816 KB |
Output is correct |
4 |
Correct |
124 ms |
17784 KB |
Output is correct |
5 |
Correct |
117 ms |
17696 KB |
Output is correct |
6 |
Correct |
165 ms |
17772 KB |
Output is correct |
7 |
Correct |
137 ms |
17788 KB |
Output is correct |
8 |
Correct |
110 ms |
17740 KB |
Output is correct |
9 |
Correct |
74 ms |
17544 KB |
Output is correct |
10 |
Correct |
122 ms |
17732 KB |
Output is correct |
11 |
Correct |
144 ms |
17688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
164 ms |
18056 KB |
Output is correct |
3 |
Correct |
185 ms |
17808 KB |
Output is correct |
4 |
Correct |
155 ms |
17716 KB |
Output is correct |
5 |
Correct |
144 ms |
17812 KB |
Output is correct |
6 |
Correct |
129 ms |
17376 KB |
Output is correct |
7 |
Correct |
150 ms |
22476 KB |
Output is correct |
8 |
Correct |
97 ms |
25608 KB |
Output is correct |
9 |
Correct |
92 ms |
10760 KB |
Output is correct |
10 |
Correct |
137 ms |
17740 KB |
Output is correct |
11 |
Correct |
143 ms |
17744 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
115 ms |
17728 KB |
Output is correct |
18 |
Correct |
126 ms |
17696 KB |
Output is correct |
19 |
Correct |
163 ms |
17144 KB |
Output is correct |
20 |
Correct |
139 ms |
17684 KB |
Output is correct |
21 |
Correct |
175 ms |
17828 KB |
Output is correct |
22 |
Correct |
149 ms |
17708 KB |
Output is correct |
23 |
Correct |
114 ms |
17688 KB |
Output is correct |
24 |
Correct |
122 ms |
17708 KB |
Output is correct |
25 |
Correct |
138 ms |
25500 KB |
Output is correct |
26 |
Correct |
161 ms |
17740 KB |
Output is correct |
27 |
Correct |
125 ms |
17744 KB |
Output is correct |
28 |
Correct |
169 ms |
17748 KB |
Output is correct |
29 |
Correct |
106 ms |
17732 KB |
Output is correct |
30 |
Correct |
75 ms |
17612 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
182 ms |
17612 KB |
Output is correct |
33 |
Correct |
179 ms |
17816 KB |
Output is correct |
34 |
Correct |
124 ms |
17784 KB |
Output is correct |
35 |
Correct |
117 ms |
17696 KB |
Output is correct |
36 |
Correct |
165 ms |
17772 KB |
Output is correct |
37 |
Correct |
137 ms |
17788 KB |
Output is correct |
38 |
Correct |
110 ms |
17740 KB |
Output is correct |
39 |
Correct |
74 ms |
17544 KB |
Output is correct |
40 |
Correct |
122 ms |
17732 KB |
Output is correct |
41 |
Correct |
144 ms |
17688 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
164 ms |
18056 KB |
Output is correct |
44 |
Correct |
185 ms |
17808 KB |
Output is correct |
45 |
Correct |
155 ms |
17716 KB |
Output is correct |
46 |
Correct |
144 ms |
17812 KB |
Output is correct |
47 |
Correct |
129 ms |
17376 KB |
Output is correct |
48 |
Correct |
150 ms |
22476 KB |
Output is correct |
49 |
Correct |
97 ms |
25608 KB |
Output is correct |
50 |
Correct |
92 ms |
10760 KB |
Output is correct |
51 |
Correct |
137 ms |
17740 KB |
Output is correct |
52 |
Correct |
143 ms |
17744 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
2 ms |
468 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
1 ms |
468 KB |
Output is correct |
61 |
Correct |
1 ms |
468 KB |
Output is correct |
62 |
Correct |
2 ms |
468 KB |
Output is correct |
63 |
Correct |
1 ms |
468 KB |
Output is correct |
64 |
Correct |
1 ms |
468 KB |
Output is correct |
65 |
Correct |
1 ms |
468 KB |
Output is correct |
66 |
Correct |
1 ms |
468 KB |
Output is correct |
67 |
Correct |
129 ms |
17684 KB |
Output is correct |
68 |
Correct |
110 ms |
17740 KB |
Output is correct |
69 |
Correct |
123 ms |
17156 KB |
Output is correct |
70 |
Correct |
126 ms |
17672 KB |
Output is correct |
71 |
Correct |
148 ms |
17796 KB |
Output is correct |
72 |
Correct |
135 ms |
17820 KB |
Output is correct |
73 |
Correct |
103 ms |
17792 KB |
Output is correct |
74 |
Correct |
103 ms |
17688 KB |
Output is correct |
75 |
Correct |
169 ms |
25620 KB |
Output is correct |
76 |
Correct |
127 ms |
17816 KB |
Output is correct |
77 |
Correct |
115 ms |
17684 KB |
Output is correct |
78 |
Correct |
139 ms |
17840 KB |
Output is correct |
79 |
Correct |
123 ms |
17704 KB |
Output is correct |
80 |
Correct |
73 ms |
17608 KB |
Output is correct |
81 |
Correct |
170 ms |
17628 KB |
Output is correct |
82 |
Correct |
194 ms |
17708 KB |
Output is correct |
83 |
Correct |
138 ms |
17792 KB |
Output is correct |
84 |
Correct |
112 ms |
17764 KB |
Output is correct |
85 |
Correct |
154 ms |
17788 KB |
Output is correct |
86 |
Correct |
127 ms |
17688 KB |
Output is correct |
87 |
Correct |
123 ms |
17684 KB |
Output is correct |
88 |
Correct |
120 ms |
17792 KB |
Output is correct |
89 |
Correct |
133 ms |
17804 KB |
Output is correct |
90 |
Correct |
161 ms |
18060 KB |
Output is correct |
91 |
Correct |
154 ms |
17740 KB |
Output is correct |
92 |
Correct |
157 ms |
17780 KB |
Output is correct |
93 |
Correct |
152 ms |
17800 KB |
Output is correct |
94 |
Correct |
158 ms |
17480 KB |
Output is correct |
95 |
Correct |
133 ms |
22516 KB |
Output is correct |
96 |
Correct |
97 ms |
25716 KB |
Output is correct |
97 |
Correct |
103 ms |
10696 KB |
Output is correct |
98 |
Correct |
125 ms |
17752 KB |
Output is correct |
99 |
Correct |
127 ms |
17724 KB |
Output is correct |
100 |
Correct |
55 ms |
2992 KB |
Output is correct |
101 |
Correct |
219 ms |
17832 KB |
Output is correct |
102 |
Correct |
141 ms |
15076 KB |
Output is correct |
103 |
Correct |
177 ms |
18448 KB |
Output is correct |
104 |
Correct |
210 ms |
18008 KB |
Output is correct |