#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 200'010;
vector<int> A0[N], A[N];
int val[N];
pii srt[N];
int n, m;
namespace dsu {
int par[N];
void init(int n) { fill(par, par+n, -1); }
int rt(int v) { return par[v] == -1? v: (par[v] = rt(par[v])); }
bool unite(int v, int u) {
v = rt(v);
u = rt(u);
if (v == u)
return 0;
par[u] = v;
return 1;
}
}
ll sum[N];
void dfs_sum(int v)
{
sum[v] = val[v];
for (int u : A[v]) {
dfs_sum(u);
sum[v] += sum[u];
}
}
bool ans[N];
void dfs_solve(int v, int pv)
{
if (sum[v] < pv)
return;
ans[v] = 1;
for (int u : A[v])
dfs_solve(u, val[v]);
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> m;
Loop (i,0,n) {
cin >> val[i];
srt[i] = {val[i], i};
}
sort(srt, srt+n);
Loop (i,0,m) {
int v, u;
cin >> v >> u;
--v; --u;
A0[v].push_back(u);
A0[u].push_back(v);
}
dsu::init(n);
Loop (i,0,n) {
int v = srt[i].second;
for (int u : A0[v]) {
if (val[v] < val[u])
continue;
if (dsu::rt(v) != dsu::rt(u)) {
A[v].push_back(dsu::rt(u));
dsu::unite(v, u);
}
}
}
dfs_sum(dsu::rt(0));
dfs_solve(dsu::rt(0), -1);
Loop (i,0,n)
cout << ans[i];
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9716 KB |
Output is correct |
2 |
Correct |
6 ms |
9716 KB |
Output is correct |
3 |
Correct |
6 ms |
9716 KB |
Output is correct |
4 |
Correct |
7 ms |
9860 KB |
Output is correct |
5 |
Correct |
7 ms |
9912 KB |
Output is correct |
6 |
Correct |
7 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
7 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
10036 KB |
Output is correct |
10 |
Correct |
8 ms |
9912 KB |
Output is correct |
11 |
Correct |
7 ms |
9860 KB |
Output is correct |
12 |
Correct |
7 ms |
9904 KB |
Output is correct |
13 |
Correct |
7 ms |
9940 KB |
Output is correct |
14 |
Correct |
7 ms |
9812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9724 KB |
Output is correct |
2 |
Correct |
6 ms |
9732 KB |
Output is correct |
3 |
Correct |
153 ms |
33496 KB |
Output is correct |
4 |
Correct |
162 ms |
32000 KB |
Output is correct |
5 |
Correct |
140 ms |
28840 KB |
Output is correct |
6 |
Correct |
193 ms |
29416 KB |
Output is correct |
7 |
Correct |
178 ms |
29352 KB |
Output is correct |
8 |
Correct |
178 ms |
29448 KB |
Output is correct |
9 |
Correct |
116 ms |
28416 KB |
Output is correct |
10 |
Correct |
91 ms |
26156 KB |
Output is correct |
11 |
Correct |
109 ms |
26108 KB |
Output is correct |
12 |
Correct |
143 ms |
27872 KB |
Output is correct |
13 |
Correct |
123 ms |
39300 KB |
Output is correct |
14 |
Correct |
132 ms |
39520 KB |
Output is correct |
15 |
Correct |
123 ms |
41044 KB |
Output is correct |
16 |
Correct |
93 ms |
40052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9720 KB |
Output is correct |
2 |
Correct |
184 ms |
29516 KB |
Output is correct |
3 |
Correct |
175 ms |
29568 KB |
Output is correct |
4 |
Correct |
140 ms |
41064 KB |
Output is correct |
5 |
Correct |
134 ms |
36336 KB |
Output is correct |
6 |
Correct |
179 ms |
29612 KB |
Output is correct |
7 |
Correct |
150 ms |
41072 KB |
Output is correct |
8 |
Correct |
136 ms |
41128 KB |
Output is correct |
9 |
Correct |
88 ms |
40144 KB |
Output is correct |
10 |
Correct |
112 ms |
32556 KB |
Output is correct |
11 |
Correct |
129 ms |
29432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9724 KB |
Output is correct |
2 |
Correct |
191 ms |
29932 KB |
Output is correct |
3 |
Correct |
211 ms |
29504 KB |
Output is correct |
4 |
Correct |
199 ms |
29548 KB |
Output is correct |
5 |
Correct |
200 ms |
30084 KB |
Output is correct |
6 |
Correct |
171 ms |
29960 KB |
Output is correct |
7 |
Correct |
117 ms |
34144 KB |
Output is correct |
8 |
Correct |
95 ms |
39816 KB |
Output is correct |
9 |
Correct |
103 ms |
21372 KB |
Output is correct |
10 |
Correct |
142 ms |
28208 KB |
Output is correct |
11 |
Correct |
141 ms |
29448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9716 KB |
Output is correct |
2 |
Correct |
6 ms |
9716 KB |
Output is correct |
3 |
Correct |
6 ms |
9716 KB |
Output is correct |
4 |
Correct |
7 ms |
9860 KB |
Output is correct |
5 |
Correct |
7 ms |
9912 KB |
Output is correct |
6 |
Correct |
7 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
7 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
10036 KB |
Output is correct |
10 |
Correct |
8 ms |
9912 KB |
Output is correct |
11 |
Correct |
7 ms |
9860 KB |
Output is correct |
12 |
Correct |
7 ms |
9904 KB |
Output is correct |
13 |
Correct |
7 ms |
9940 KB |
Output is correct |
14 |
Correct |
7 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9724 KB |
Output is correct |
16 |
Correct |
6 ms |
9732 KB |
Output is correct |
17 |
Correct |
153 ms |
33496 KB |
Output is correct |
18 |
Correct |
162 ms |
32000 KB |
Output is correct |
19 |
Correct |
140 ms |
28840 KB |
Output is correct |
20 |
Correct |
193 ms |
29416 KB |
Output is correct |
21 |
Correct |
178 ms |
29352 KB |
Output is correct |
22 |
Correct |
178 ms |
29448 KB |
Output is correct |
23 |
Correct |
116 ms |
28416 KB |
Output is correct |
24 |
Correct |
91 ms |
26156 KB |
Output is correct |
25 |
Correct |
109 ms |
26108 KB |
Output is correct |
26 |
Correct |
143 ms |
27872 KB |
Output is correct |
27 |
Correct |
123 ms |
39300 KB |
Output is correct |
28 |
Correct |
132 ms |
39520 KB |
Output is correct |
29 |
Correct |
123 ms |
41044 KB |
Output is correct |
30 |
Correct |
93 ms |
40052 KB |
Output is correct |
31 |
Correct |
5 ms |
9720 KB |
Output is correct |
32 |
Correct |
184 ms |
29516 KB |
Output is correct |
33 |
Correct |
175 ms |
29568 KB |
Output is correct |
34 |
Correct |
140 ms |
41064 KB |
Output is correct |
35 |
Correct |
134 ms |
36336 KB |
Output is correct |
36 |
Correct |
179 ms |
29612 KB |
Output is correct |
37 |
Correct |
150 ms |
41072 KB |
Output is correct |
38 |
Correct |
136 ms |
41128 KB |
Output is correct |
39 |
Correct |
88 ms |
40144 KB |
Output is correct |
40 |
Correct |
112 ms |
32556 KB |
Output is correct |
41 |
Correct |
129 ms |
29432 KB |
Output is correct |
42 |
Correct |
5 ms |
9724 KB |
Output is correct |
43 |
Correct |
191 ms |
29932 KB |
Output is correct |
44 |
Correct |
211 ms |
29504 KB |
Output is correct |
45 |
Correct |
199 ms |
29548 KB |
Output is correct |
46 |
Correct |
200 ms |
30084 KB |
Output is correct |
47 |
Correct |
171 ms |
29960 KB |
Output is correct |
48 |
Correct |
117 ms |
34144 KB |
Output is correct |
49 |
Correct |
95 ms |
39816 KB |
Output is correct |
50 |
Correct |
103 ms |
21372 KB |
Output is correct |
51 |
Correct |
142 ms |
28208 KB |
Output is correct |
52 |
Correct |
141 ms |
29448 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9716 KB |
Output is correct |
55 |
Correct |
5 ms |
9720 KB |
Output is correct |
56 |
Correct |
5 ms |
9856 KB |
Output is correct |
57 |
Correct |
7 ms |
9812 KB |
Output is correct |
58 |
Correct |
5 ms |
9812 KB |
Output is correct |
59 |
Correct |
6 ms |
9900 KB |
Output is correct |
60 |
Correct |
6 ms |
9884 KB |
Output is correct |
61 |
Correct |
5 ms |
9940 KB |
Output is correct |
62 |
Correct |
6 ms |
9812 KB |
Output is correct |
63 |
Correct |
7 ms |
9812 KB |
Output is correct |
64 |
Correct |
6 ms |
9812 KB |
Output is correct |
65 |
Correct |
6 ms |
9940 KB |
Output is correct |
66 |
Correct |
7 ms |
9884 KB |
Output is correct |
67 |
Correct |
133 ms |
33500 KB |
Output is correct |
68 |
Correct |
141 ms |
31928 KB |
Output is correct |
69 |
Correct |
167 ms |
28736 KB |
Output is correct |
70 |
Correct |
153 ms |
29416 KB |
Output is correct |
71 |
Correct |
157 ms |
29352 KB |
Output is correct |
72 |
Correct |
165 ms |
29456 KB |
Output is correct |
73 |
Correct |
130 ms |
28404 KB |
Output is correct |
74 |
Correct |
89 ms |
26048 KB |
Output is correct |
75 |
Correct |
102 ms |
26116 KB |
Output is correct |
76 |
Correct |
162 ms |
27892 KB |
Output is correct |
77 |
Correct |
140 ms |
39524 KB |
Output is correct |
78 |
Correct |
154 ms |
39492 KB |
Output is correct |
79 |
Correct |
133 ms |
41040 KB |
Output is correct |
80 |
Correct |
87 ms |
40052 KB |
Output is correct |
81 |
Correct |
182 ms |
29548 KB |
Output is correct |
82 |
Correct |
189 ms |
29668 KB |
Output is correct |
83 |
Correct |
165 ms |
41104 KB |
Output is correct |
84 |
Correct |
127 ms |
36344 KB |
Output is correct |
85 |
Correct |
183 ms |
29584 KB |
Output is correct |
86 |
Correct |
169 ms |
41124 KB |
Output is correct |
87 |
Correct |
157 ms |
41116 KB |
Output is correct |
88 |
Correct |
149 ms |
32652 KB |
Output is correct |
89 |
Correct |
146 ms |
29440 KB |
Output is correct |
90 |
Correct |
221 ms |
29932 KB |
Output is correct |
91 |
Correct |
217 ms |
29496 KB |
Output is correct |
92 |
Correct |
220 ms |
29564 KB |
Output is correct |
93 |
Correct |
249 ms |
29980 KB |
Output is correct |
94 |
Correct |
217 ms |
29912 KB |
Output is correct |
95 |
Correct |
134 ms |
34128 KB |
Output is correct |
96 |
Correct |
101 ms |
39840 KB |
Output is correct |
97 |
Correct |
111 ms |
21484 KB |
Output is correct |
98 |
Correct |
210 ms |
28244 KB |
Output is correct |
99 |
Correct |
150 ms |
29372 KB |
Output is correct |
100 |
Correct |
53 ms |
14108 KB |
Output is correct |
101 |
Correct |
243 ms |
29536 KB |
Output is correct |
102 |
Correct |
146 ms |
26700 KB |
Output is correct |
103 |
Correct |
162 ms |
29312 KB |
Output is correct |
104 |
Correct |
193 ms |
30208 KB |
Output is correct |