#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
#define fi first
#define si second
#define ar array
#define pb push_back
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
typedef vector<int> vi;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int N = 200010;
int n, m;
int s[N], p[N], vis[N], bad[N];
ll val[N];
vector<int> g[N];
vector<int> st[N];
int par(int x) {return p[x];}
bool same(int x, int y) {return par(x) == par(y);}
void merge(int x, int y) {
x = par(x), y = par(y);
if (st[x].size() < st[y].size()) swap(x, y);
if (x == y) return;
val[x] += val[y];
while (st[y].size()) {
int v = st[y].back();
st[y].pop_back();
p[v] = x;
st[x].pb(v);
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin.exceptions(ios::badbit|ios::failbit);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> s[i];
val[i] = s[i];
p[i] = i;
st[i] = vector<int>(1, i);
}
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b;
--a, --b;
g[a].pb(b);
g[b].pb(a);
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int x, int y) {
return s[x] < s[y];
});
for (auto i: order) {
vis[i] = 1;
sort(g[i].begin(), g[i].end(), [&](int x, int y) {
return s[x] < s[y];
});
for (auto j: g[i]) {
if (same(i, j)) continue;
if (vis[j]) {
if (s[i] > val[par(j)]) {
for (auto v: st[par(j)]) {
bad[v] = 1;
}
}
merge(i, j);
}
if (val[par(i)] >= s[j]) {
merge(i, j);
}
}
}
for (int i = 0; i < n; ++i) {
cout << (bad[i] ? 0 : 1);
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16984 KB |
Output is correct |
2 |
Correct |
3 ms |
16988 KB |
Output is correct |
3 |
Correct |
4 ms |
14940 KB |
Output is correct |
4 |
Correct |
4 ms |
16988 KB |
Output is correct |
5 |
Correct |
5 ms |
17140 KB |
Output is correct |
6 |
Correct |
4 ms |
17244 KB |
Output is correct |
7 |
Correct |
4 ms |
17244 KB |
Output is correct |
8 |
Correct |
4 ms |
16988 KB |
Output is correct |
9 |
Correct |
4 ms |
17244 KB |
Output is correct |
10 |
Correct |
4 ms |
17244 KB |
Output is correct |
11 |
Correct |
4 ms |
17204 KB |
Output is correct |
12 |
Correct |
5 ms |
17244 KB |
Output is correct |
13 |
Correct |
4 ms |
17244 KB |
Output is correct |
14 |
Correct |
5 ms |
17240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Correct |
3 ms |
14952 KB |
Output is correct |
3 |
Correct |
109 ms |
35780 KB |
Output is correct |
4 |
Correct |
107 ms |
40644 KB |
Output is correct |
5 |
Correct |
151 ms |
43068 KB |
Output is correct |
6 |
Correct |
160 ms |
43852 KB |
Output is correct |
7 |
Correct |
174 ms |
48004 KB |
Output is correct |
8 |
Correct |
206 ms |
42352 KB |
Output is correct |
9 |
Correct |
126 ms |
58540 KB |
Output is correct |
10 |
Correct |
98 ms |
39360 KB |
Output is correct |
11 |
Correct |
101 ms |
39324 KB |
Output is correct |
12 |
Correct |
154 ms |
42548 KB |
Output is correct |
13 |
Correct |
103 ms |
43364 KB |
Output is correct |
14 |
Correct |
110 ms |
42900 KB |
Output is correct |
15 |
Correct |
138 ms |
37712 KB |
Output is correct |
16 |
Correct |
72 ms |
36800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
203 ms |
46360 KB |
Output is correct |
3 |
Correct |
195 ms |
50240 KB |
Output is correct |
4 |
Correct |
118 ms |
44480 KB |
Output is correct |
5 |
Correct |
109 ms |
43580 KB |
Output is correct |
6 |
Correct |
215 ms |
50128 KB |
Output is correct |
7 |
Correct |
111 ms |
37548 KB |
Output is correct |
8 |
Correct |
107 ms |
37576 KB |
Output is correct |
9 |
Correct |
73 ms |
37096 KB |
Output is correct |
10 |
Correct |
109 ms |
42944 KB |
Output is correct |
11 |
Correct |
146 ms |
45360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
209 ms |
39148 KB |
Output is correct |
3 |
Correct |
181 ms |
43720 KB |
Output is correct |
4 |
Correct |
224 ms |
45608 KB |
Output is correct |
5 |
Correct |
161 ms |
44436 KB |
Output is correct |
6 |
Correct |
153 ms |
40904 KB |
Output is correct |
7 |
Correct |
108 ms |
39832 KB |
Output is correct |
8 |
Correct |
87 ms |
41588 KB |
Output is correct |
9 |
Correct |
84 ms |
31140 KB |
Output is correct |
10 |
Correct |
156 ms |
44328 KB |
Output is correct |
11 |
Correct |
159 ms |
45524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16984 KB |
Output is correct |
2 |
Correct |
3 ms |
16988 KB |
Output is correct |
3 |
Correct |
4 ms |
14940 KB |
Output is correct |
4 |
Correct |
4 ms |
16988 KB |
Output is correct |
5 |
Correct |
5 ms |
17140 KB |
Output is correct |
6 |
Correct |
4 ms |
17244 KB |
Output is correct |
7 |
Correct |
4 ms |
17244 KB |
Output is correct |
8 |
Correct |
4 ms |
16988 KB |
Output is correct |
9 |
Correct |
4 ms |
17244 KB |
Output is correct |
10 |
Correct |
4 ms |
17244 KB |
Output is correct |
11 |
Correct |
4 ms |
17204 KB |
Output is correct |
12 |
Correct |
5 ms |
17244 KB |
Output is correct |
13 |
Correct |
4 ms |
17244 KB |
Output is correct |
14 |
Correct |
5 ms |
17240 KB |
Output is correct |
15 |
Correct |
3 ms |
16988 KB |
Output is correct |
16 |
Correct |
3 ms |
14952 KB |
Output is correct |
17 |
Correct |
109 ms |
35780 KB |
Output is correct |
18 |
Correct |
107 ms |
40644 KB |
Output is correct |
19 |
Correct |
151 ms |
43068 KB |
Output is correct |
20 |
Correct |
160 ms |
43852 KB |
Output is correct |
21 |
Correct |
174 ms |
48004 KB |
Output is correct |
22 |
Correct |
206 ms |
42352 KB |
Output is correct |
23 |
Correct |
126 ms |
58540 KB |
Output is correct |
24 |
Correct |
98 ms |
39360 KB |
Output is correct |
25 |
Correct |
101 ms |
39324 KB |
Output is correct |
26 |
Correct |
154 ms |
42548 KB |
Output is correct |
27 |
Correct |
103 ms |
43364 KB |
Output is correct |
28 |
Correct |
110 ms |
42900 KB |
Output is correct |
29 |
Correct |
138 ms |
37712 KB |
Output is correct |
30 |
Correct |
72 ms |
36800 KB |
Output is correct |
31 |
Correct |
3 ms |
14940 KB |
Output is correct |
32 |
Correct |
203 ms |
46360 KB |
Output is correct |
33 |
Correct |
195 ms |
50240 KB |
Output is correct |
34 |
Correct |
118 ms |
44480 KB |
Output is correct |
35 |
Correct |
109 ms |
43580 KB |
Output is correct |
36 |
Correct |
215 ms |
50128 KB |
Output is correct |
37 |
Correct |
111 ms |
37548 KB |
Output is correct |
38 |
Correct |
107 ms |
37576 KB |
Output is correct |
39 |
Correct |
73 ms |
37096 KB |
Output is correct |
40 |
Correct |
109 ms |
42944 KB |
Output is correct |
41 |
Correct |
146 ms |
45360 KB |
Output is correct |
42 |
Correct |
3 ms |
14936 KB |
Output is correct |
43 |
Correct |
209 ms |
39148 KB |
Output is correct |
44 |
Correct |
181 ms |
43720 KB |
Output is correct |
45 |
Correct |
224 ms |
45608 KB |
Output is correct |
46 |
Correct |
161 ms |
44436 KB |
Output is correct |
47 |
Correct |
153 ms |
40904 KB |
Output is correct |
48 |
Correct |
108 ms |
39832 KB |
Output is correct |
49 |
Correct |
87 ms |
41588 KB |
Output is correct |
50 |
Correct |
84 ms |
31140 KB |
Output is correct |
51 |
Correct |
156 ms |
44328 KB |
Output is correct |
52 |
Correct |
159 ms |
45524 KB |
Output is correct |
53 |
Correct |
3 ms |
16988 KB |
Output is correct |
54 |
Correct |
3 ms |
17036 KB |
Output is correct |
55 |
Correct |
3 ms |
14996 KB |
Output is correct |
56 |
Correct |
4 ms |
17244 KB |
Output is correct |
57 |
Correct |
4 ms |
17240 KB |
Output is correct |
58 |
Correct |
4 ms |
17496 KB |
Output is correct |
59 |
Correct |
4 ms |
17240 KB |
Output is correct |
60 |
Correct |
4 ms |
16988 KB |
Output is correct |
61 |
Correct |
4 ms |
17284 KB |
Output is correct |
62 |
Correct |
5 ms |
17244 KB |
Output is correct |
63 |
Correct |
5 ms |
17136 KB |
Output is correct |
64 |
Correct |
4 ms |
17240 KB |
Output is correct |
65 |
Correct |
5 ms |
17336 KB |
Output is correct |
66 |
Correct |
4 ms |
17244 KB |
Output is correct |
67 |
Correct |
109 ms |
39828 KB |
Output is correct |
68 |
Correct |
115 ms |
43460 KB |
Output is correct |
69 |
Correct |
157 ms |
46648 KB |
Output is correct |
70 |
Correct |
168 ms |
47724 KB |
Output is correct |
71 |
Correct |
163 ms |
47960 KB |
Output is correct |
72 |
Correct |
169 ms |
42168 KB |
Output is correct |
73 |
Correct |
130 ms |
58588 KB |
Output is correct |
74 |
Correct |
105 ms |
39332 KB |
Output is correct |
75 |
Correct |
104 ms |
39792 KB |
Output is correct |
76 |
Correct |
198 ms |
42536 KB |
Output is correct |
77 |
Correct |
118 ms |
43712 KB |
Output is correct |
78 |
Correct |
101 ms |
42800 KB |
Output is correct |
79 |
Correct |
95 ms |
37624 KB |
Output is correct |
80 |
Correct |
72 ms |
36808 KB |
Output is correct |
81 |
Correct |
219 ms |
49908 KB |
Output is correct |
82 |
Correct |
186 ms |
50160 KB |
Output is correct |
83 |
Correct |
119 ms |
44612 KB |
Output is correct |
84 |
Correct |
100 ms |
43684 KB |
Output is correct |
85 |
Correct |
209 ms |
50260 KB |
Output is correct |
86 |
Correct |
110 ms |
37592 KB |
Output is correct |
87 |
Correct |
131 ms |
37664 KB |
Output is correct |
88 |
Correct |
129 ms |
42884 KB |
Output is correct |
89 |
Correct |
154 ms |
45168 KB |
Output is correct |
90 |
Correct |
192 ms |
42820 KB |
Output is correct |
91 |
Correct |
236 ms |
43972 KB |
Output is correct |
92 |
Correct |
187 ms |
45600 KB |
Output is correct |
93 |
Correct |
156 ms |
44488 KB |
Output is correct |
94 |
Correct |
153 ms |
40724 KB |
Output is correct |
95 |
Correct |
99 ms |
40240 KB |
Output is correct |
96 |
Correct |
86 ms |
41480 KB |
Output is correct |
97 |
Correct |
96 ms |
31308 KB |
Output is correct |
98 |
Correct |
161 ms |
44196 KB |
Output is correct |
99 |
Correct |
166 ms |
45644 KB |
Output is correct |
100 |
Correct |
43 ms |
23480 KB |
Output is correct |
101 |
Correct |
203 ms |
46152 KB |
Output is correct |
102 |
Correct |
142 ms |
37664 KB |
Output is correct |
103 |
Correct |
182 ms |
38464 KB |
Output is correct |
104 |
Correct |
240 ms |
42440 KB |
Output is correct |