#include <bits/stdc++.h>
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(iter(a), greater<>())
#define eb emplace_back
#define ef emplace_front
#define pob pop_back()
#define pof pop_front()
#define mp make_pair
#define F first
#define S second
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
int n, m;
vector<int> dsu;
vector<int> id;
vector<ll> sum;
vector<vector<int>> g;
vector<bool> no;
int ts;
vector<bool> ans;
void init(){
dsu.resize(n + 1);
iota(iter(dsu), 0);
id.resize(n + 1);
iota(iter(id), 0);
g.resize(2 * n + 1);
no.resize(2 * n + 1);
sum.resize(n + 1);
ans.resize(n + 1);
ts = n;
}
int findDSU(int a){
if(dsu[a] != a) dsu[a] = findDSU(dsu[a]);
return dsu[a];
}
int unionDSU(int a, int b){
a = findDSU(a);
b = findDSU(b);
assert(a != b);
dsu[b] = a;
sum[a] += sum[b];
return id[a] = ++ts;
}
void dfs(int now, bool t){
if(no[now]) t = false;
if(now <= n) ans[now] = t;
for(int i : g[now]){
dfs(i, t);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
init();
vector<int> s(n + 1);
for(int i = 1; i <= n; i++){
cin >> s[i];
sum[i] = s[i];
}
vector<pii> e;
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v;
if(s[u] < s[v]) swap(u, v);
e.eb(mp(u, v));
}
sort(iter(e), [&](pii x, pii y){ return s[x.F] < s[y.F]; });
for(pii i : e){
int u, v;
tie(u, v) = i;
if(findDSU(u) == findDSU(v)) continue;
v = findDSU(v);
if(sum[v] < s[u]) no[id[v]] = true;
u = findDSU(u);
int t1 = id[u], t2 = id[v];
int p = unionDSU(u, v);
g[p].eb(t1);
g[p].eb(t2);
}
int rt = id[findDSU(1)];
dfs(rt, true);
for(int i = 1; i <= n; i++) cout << ans[i];
cout << "\n";
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 |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
480 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 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 |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 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 |
125 ms |
24892 KB |
Output is correct |
4 |
Correct |
131 ms |
21728 KB |
Output is correct |
5 |
Correct |
129 ms |
21136 KB |
Output is correct |
6 |
Correct |
135 ms |
21696 KB |
Output is correct |
7 |
Correct |
154 ms |
21692 KB |
Output is correct |
8 |
Correct |
151 ms |
21764 KB |
Output is correct |
9 |
Correct |
114 ms |
21624 KB |
Output is correct |
10 |
Correct |
97 ms |
27912 KB |
Output is correct |
11 |
Correct |
115 ms |
27948 KB |
Output is correct |
12 |
Correct |
146 ms |
21672 KB |
Output is correct |
13 |
Correct |
124 ms |
21664 KB |
Output is correct |
14 |
Correct |
116 ms |
21724 KB |
Output is correct |
15 |
Correct |
125 ms |
27964 KB |
Output is correct |
16 |
Correct |
105 ms |
27604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
158 ms |
21604 KB |
Output is correct |
3 |
Correct |
154 ms |
21808 KB |
Output is correct |
4 |
Correct |
138 ms |
21664 KB |
Output is correct |
5 |
Correct |
140 ms |
21676 KB |
Output is correct |
6 |
Correct |
139 ms |
21628 KB |
Output is correct |
7 |
Correct |
113 ms |
27896 KB |
Output is correct |
8 |
Correct |
114 ms |
27992 KB |
Output is correct |
9 |
Correct |
98 ms |
27704 KB |
Output is correct |
10 |
Correct |
132 ms |
21688 KB |
Output is correct |
11 |
Correct |
126 ms |
21652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
166 ms |
22084 KB |
Output is correct |
3 |
Correct |
163 ms |
21628 KB |
Output is correct |
4 |
Correct |
178 ms |
21716 KB |
Output is correct |
5 |
Correct |
165 ms |
21756 KB |
Output is correct |
6 |
Correct |
146 ms |
21344 KB |
Output is correct |
7 |
Correct |
132 ms |
27948 KB |
Output is correct |
8 |
Correct |
103 ms |
24836 KB |
Output is correct |
9 |
Correct |
91 ms |
12064 KB |
Output is correct |
10 |
Correct |
195 ms |
21692 KB |
Output is correct |
11 |
Correct |
141 ms |
21672 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 |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
480 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 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 |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 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 |
125 ms |
24892 KB |
Output is correct |
18 |
Correct |
131 ms |
21728 KB |
Output is correct |
19 |
Correct |
129 ms |
21136 KB |
Output is correct |
20 |
Correct |
135 ms |
21696 KB |
Output is correct |
21 |
Correct |
154 ms |
21692 KB |
Output is correct |
22 |
Correct |
151 ms |
21764 KB |
Output is correct |
23 |
Correct |
114 ms |
21624 KB |
Output is correct |
24 |
Correct |
97 ms |
27912 KB |
Output is correct |
25 |
Correct |
115 ms |
27948 KB |
Output is correct |
26 |
Correct |
146 ms |
21672 KB |
Output is correct |
27 |
Correct |
124 ms |
21664 KB |
Output is correct |
28 |
Correct |
116 ms |
21724 KB |
Output is correct |
29 |
Correct |
125 ms |
27964 KB |
Output is correct |
30 |
Correct |
105 ms |
27604 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
158 ms |
21604 KB |
Output is correct |
33 |
Correct |
154 ms |
21808 KB |
Output is correct |
34 |
Correct |
138 ms |
21664 KB |
Output is correct |
35 |
Correct |
140 ms |
21676 KB |
Output is correct |
36 |
Correct |
139 ms |
21628 KB |
Output is correct |
37 |
Correct |
113 ms |
27896 KB |
Output is correct |
38 |
Correct |
114 ms |
27992 KB |
Output is correct |
39 |
Correct |
98 ms |
27704 KB |
Output is correct |
40 |
Correct |
132 ms |
21688 KB |
Output is correct |
41 |
Correct |
126 ms |
21652 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
166 ms |
22084 KB |
Output is correct |
44 |
Correct |
163 ms |
21628 KB |
Output is correct |
45 |
Correct |
178 ms |
21716 KB |
Output is correct |
46 |
Correct |
165 ms |
21756 KB |
Output is correct |
47 |
Correct |
146 ms |
21344 KB |
Output is correct |
48 |
Correct |
132 ms |
27948 KB |
Output is correct |
49 |
Correct |
103 ms |
24836 KB |
Output is correct |
50 |
Correct |
91 ms |
12064 KB |
Output is correct |
51 |
Correct |
195 ms |
21692 KB |
Output is correct |
52 |
Correct |
141 ms |
21672 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
2 ms |
468 KB |
Output is correct |
57 |
Correct |
2 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
468 KB |
Output is correct |
59 |
Correct |
2 ms |
468 KB |
Output is correct |
60 |
Correct |
2 ms |
444 KB |
Output is correct |
61 |
Correct |
2 ms |
468 KB |
Output is correct |
62 |
Correct |
1 ms |
468 KB |
Output is correct |
63 |
Correct |
1 ms |
468 KB |
Output is correct |
64 |
Correct |
2 ms |
468 KB |
Output is correct |
65 |
Correct |
1 ms |
468 KB |
Output is correct |
66 |
Correct |
1 ms |
536 KB |
Output is correct |
67 |
Correct |
129 ms |
24948 KB |
Output is correct |
68 |
Correct |
146 ms |
21672 KB |
Output is correct |
69 |
Correct |
146 ms |
21024 KB |
Output is correct |
70 |
Correct |
163 ms |
21688 KB |
Output is correct |
71 |
Correct |
152 ms |
21768 KB |
Output is correct |
72 |
Correct |
177 ms |
21728 KB |
Output is correct |
73 |
Correct |
142 ms |
21640 KB |
Output is correct |
74 |
Correct |
116 ms |
27936 KB |
Output is correct |
75 |
Correct |
141 ms |
27912 KB |
Output is correct |
76 |
Correct |
188 ms |
21664 KB |
Output is correct |
77 |
Correct |
149 ms |
21700 KB |
Output is correct |
78 |
Correct |
143 ms |
21672 KB |
Output is correct |
79 |
Correct |
135 ms |
27892 KB |
Output is correct |
80 |
Correct |
94 ms |
27644 KB |
Output is correct |
81 |
Correct |
188 ms |
21584 KB |
Output is correct |
82 |
Correct |
182 ms |
21624 KB |
Output is correct |
83 |
Correct |
165 ms |
21628 KB |
Output is correct |
84 |
Correct |
126 ms |
21672 KB |
Output is correct |
85 |
Correct |
162 ms |
21664 KB |
Output is correct |
86 |
Correct |
141 ms |
27960 KB |
Output is correct |
87 |
Correct |
147 ms |
27952 KB |
Output is correct |
88 |
Correct |
176 ms |
21668 KB |
Output is correct |
89 |
Correct |
133 ms |
21692 KB |
Output is correct |
90 |
Correct |
180 ms |
22060 KB |
Output is correct |
91 |
Correct |
165 ms |
21692 KB |
Output is correct |
92 |
Correct |
172 ms |
21700 KB |
Output is correct |
93 |
Correct |
139 ms |
21692 KB |
Output is correct |
94 |
Correct |
169 ms |
21404 KB |
Output is correct |
95 |
Correct |
124 ms |
27948 KB |
Output is correct |
96 |
Correct |
96 ms |
24788 KB |
Output is correct |
97 |
Correct |
131 ms |
12032 KB |
Output is correct |
98 |
Correct |
142 ms |
21692 KB |
Output is correct |
99 |
Correct |
129 ms |
21636 KB |
Output is correct |
100 |
Correct |
45 ms |
2760 KB |
Output is correct |
101 |
Correct |
172 ms |
21888 KB |
Output is correct |
102 |
Correct |
117 ms |
18432 KB |
Output is correct |
103 |
Correct |
135 ms |
20520 KB |
Output is correct |
104 |
Correct |
151 ms |
22292 KB |
Output is correct |