#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i<=(b); i++)
#define repa(i,a,b) for(int i = (a); i>=(b); i--)
#define pll pair<lli,lli>
#define MAX 200000
//para el vector de orden
#define id second
lli n,m,a,b,total;
lli arr[MAX+2],raiz[MAX+2],uf[MAX+2],sum[MAX+2],res[MAX+2];
vector<lli> aristas[MAX+2],n_arbol[MAX+2];
vector<pll> orden;
lli sube(lli pos) {
//debugsl(pos);
//debug(uf[pos]);
if (uf[pos] == pos) return pos;
uf[pos] = sube(uf[pos]);
return uf[pos];
}
void dfs(lli pos) {
res[pos] = 1;
for(auto h : n_arbol[pos]) dfs(h);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
rep(i,1,n) {
cin >> arr[i];
orden.push_back({arr[i],i});
uf[i] = i;
sum[i] = arr[i];
raiz[i] = 1;
total += arr[i];
}
rep(i,1,m) {
cin >> a >> b;
aristas[a].push_back(b);
aristas[b].push_back(a);
}
sort(orden.begin(), orden.end());
//debug("llego");
for(auto act : orden) {
//debugsl(act.first);
//debug(act.id);
lli soy = sube(act.id);
for(auto h : aristas[act.id]) {
if (arr[h] > arr[act.id]) continue;
//debug("llego");
//debugsl(h);
//debug(uf[1]);
a = sube(h);
if(a == soy) continue;
if (sum[a] >= arr[act.id]) {
n_arbol[soy].push_back(a);
raiz[a] = 0;
}
sum[soy] += sum[a];
uf[a] = soy;
}
}
//debug("salgo");
rep(i,1,n) {
if (!raiz[i]) continue;
if (sum[i] == total) dfs(i);
}
rep(i,1,n) cout << res[i];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9704 KB |
Output is correct |
3 |
Correct |
5 ms |
9812 KB |
Output is correct |
4 |
Correct |
5 ms |
9972 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9940 KB |
Output is correct |
7 |
Correct |
6 ms |
9940 KB |
Output is correct |
8 |
Correct |
6 ms |
9864 KB |
Output is correct |
9 |
Correct |
6 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9860 KB |
Output is correct |
11 |
Correct |
5 ms |
9932 KB |
Output is correct |
12 |
Correct |
5 ms |
9940 KB |
Output is correct |
13 |
Correct |
5 ms |
9960 KB |
Output is correct |
14 |
Correct |
5 ms |
9940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9728 KB |
Output is correct |
3 |
Correct |
115 ms |
37280 KB |
Output is correct |
4 |
Correct |
92 ms |
33272 KB |
Output is correct |
5 |
Correct |
150 ms |
34120 KB |
Output is correct |
6 |
Correct |
127 ms |
34852 KB |
Output is correct |
7 |
Correct |
130 ms |
34992 KB |
Output is correct |
8 |
Correct |
123 ms |
36204 KB |
Output is correct |
9 |
Correct |
155 ms |
33596 KB |
Output is correct |
10 |
Correct |
84 ms |
30624 KB |
Output is correct |
11 |
Correct |
106 ms |
35604 KB |
Output is correct |
12 |
Correct |
123 ms |
32032 KB |
Output is correct |
13 |
Correct |
85 ms |
32044 KB |
Output is correct |
14 |
Correct |
88 ms |
32276 KB |
Output is correct |
15 |
Correct |
105 ms |
41304 KB |
Output is correct |
16 |
Correct |
78 ms |
40320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
173 ms |
33768 KB |
Output is correct |
3 |
Correct |
141 ms |
33956 KB |
Output is correct |
4 |
Correct |
112 ms |
35116 KB |
Output is correct |
5 |
Correct |
97 ms |
31544 KB |
Output is correct |
6 |
Correct |
132 ms |
34000 KB |
Output is correct |
7 |
Correct |
121 ms |
41272 KB |
Output is correct |
8 |
Correct |
126 ms |
41276 KB |
Output is correct |
9 |
Correct |
80 ms |
40324 KB |
Output is correct |
10 |
Correct |
122 ms |
35712 KB |
Output is correct |
11 |
Correct |
118 ms |
31868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
153 ms |
35320 KB |
Output is correct |
3 |
Correct |
174 ms |
35144 KB |
Output is correct |
4 |
Correct |
155 ms |
35420 KB |
Output is correct |
5 |
Correct |
147 ms |
35592 KB |
Output is correct |
6 |
Correct |
134 ms |
34812 KB |
Output is correct |
7 |
Correct |
122 ms |
39336 KB |
Output is correct |
8 |
Correct |
85 ms |
36824 KB |
Output is correct |
9 |
Correct |
85 ms |
25636 KB |
Output is correct |
10 |
Correct |
119 ms |
32580 KB |
Output is correct |
11 |
Correct |
111 ms |
31972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9704 KB |
Output is correct |
3 |
Correct |
5 ms |
9812 KB |
Output is correct |
4 |
Correct |
5 ms |
9972 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9940 KB |
Output is correct |
7 |
Correct |
6 ms |
9940 KB |
Output is correct |
8 |
Correct |
6 ms |
9864 KB |
Output is correct |
9 |
Correct |
6 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9860 KB |
Output is correct |
11 |
Correct |
5 ms |
9932 KB |
Output is correct |
12 |
Correct |
5 ms |
9940 KB |
Output is correct |
13 |
Correct |
5 ms |
9960 KB |
Output is correct |
14 |
Correct |
5 ms |
9940 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
4 ms |
9728 KB |
Output is correct |
17 |
Correct |
115 ms |
37280 KB |
Output is correct |
18 |
Correct |
92 ms |
33272 KB |
Output is correct |
19 |
Correct |
150 ms |
34120 KB |
Output is correct |
20 |
Correct |
127 ms |
34852 KB |
Output is correct |
21 |
Correct |
130 ms |
34992 KB |
Output is correct |
22 |
Correct |
123 ms |
36204 KB |
Output is correct |
23 |
Correct |
155 ms |
33596 KB |
Output is correct |
24 |
Correct |
84 ms |
30624 KB |
Output is correct |
25 |
Correct |
106 ms |
35604 KB |
Output is correct |
26 |
Correct |
123 ms |
32032 KB |
Output is correct |
27 |
Correct |
85 ms |
32044 KB |
Output is correct |
28 |
Correct |
88 ms |
32276 KB |
Output is correct |
29 |
Correct |
105 ms |
41304 KB |
Output is correct |
30 |
Correct |
78 ms |
40320 KB |
Output is correct |
31 |
Correct |
6 ms |
9684 KB |
Output is correct |
32 |
Correct |
173 ms |
33768 KB |
Output is correct |
33 |
Correct |
141 ms |
33956 KB |
Output is correct |
34 |
Correct |
112 ms |
35116 KB |
Output is correct |
35 |
Correct |
97 ms |
31544 KB |
Output is correct |
36 |
Correct |
132 ms |
34000 KB |
Output is correct |
37 |
Correct |
121 ms |
41272 KB |
Output is correct |
38 |
Correct |
126 ms |
41276 KB |
Output is correct |
39 |
Correct |
80 ms |
40324 KB |
Output is correct |
40 |
Correct |
122 ms |
35712 KB |
Output is correct |
41 |
Correct |
118 ms |
31868 KB |
Output is correct |
42 |
Correct |
4 ms |
9684 KB |
Output is correct |
43 |
Correct |
153 ms |
35320 KB |
Output is correct |
44 |
Correct |
174 ms |
35144 KB |
Output is correct |
45 |
Correct |
155 ms |
35420 KB |
Output is correct |
46 |
Correct |
147 ms |
35592 KB |
Output is correct |
47 |
Correct |
134 ms |
34812 KB |
Output is correct |
48 |
Correct |
122 ms |
39336 KB |
Output is correct |
49 |
Correct |
85 ms |
36824 KB |
Output is correct |
50 |
Correct |
85 ms |
25636 KB |
Output is correct |
51 |
Correct |
119 ms |
32580 KB |
Output is correct |
52 |
Correct |
111 ms |
31972 KB |
Output is correct |
53 |
Correct |
4 ms |
9724 KB |
Output is correct |
54 |
Correct |
4 ms |
9724 KB |
Output is correct |
55 |
Correct |
4 ms |
9728 KB |
Output is correct |
56 |
Correct |
7 ms |
10104 KB |
Output is correct |
57 |
Correct |
6 ms |
9940 KB |
Output is correct |
58 |
Correct |
5 ms |
9864 KB |
Output is correct |
59 |
Correct |
5 ms |
9860 KB |
Output is correct |
60 |
Correct |
5 ms |
9940 KB |
Output is correct |
61 |
Correct |
5 ms |
9940 KB |
Output is correct |
62 |
Correct |
5 ms |
9864 KB |
Output is correct |
63 |
Correct |
6 ms |
9940 KB |
Output is correct |
64 |
Correct |
5 ms |
9976 KB |
Output is correct |
65 |
Correct |
5 ms |
9892 KB |
Output is correct |
66 |
Correct |
6 ms |
9940 KB |
Output is correct |
67 |
Correct |
110 ms |
37264 KB |
Output is correct |
68 |
Correct |
94 ms |
33228 KB |
Output is correct |
69 |
Correct |
114 ms |
34116 KB |
Output is correct |
70 |
Correct |
116 ms |
34920 KB |
Output is correct |
71 |
Correct |
121 ms |
34956 KB |
Output is correct |
72 |
Correct |
120 ms |
36084 KB |
Output is correct |
73 |
Correct |
120 ms |
33596 KB |
Output is correct |
74 |
Correct |
91 ms |
30664 KB |
Output is correct |
75 |
Correct |
108 ms |
35640 KB |
Output is correct |
76 |
Correct |
107 ms |
32064 KB |
Output is correct |
77 |
Correct |
101 ms |
32072 KB |
Output is correct |
78 |
Correct |
97 ms |
32196 KB |
Output is correct |
79 |
Correct |
110 ms |
41312 KB |
Output is correct |
80 |
Correct |
87 ms |
40248 KB |
Output is correct |
81 |
Correct |
177 ms |
33848 KB |
Output is correct |
82 |
Correct |
149 ms |
34052 KB |
Output is correct |
83 |
Correct |
110 ms |
35128 KB |
Output is correct |
84 |
Correct |
92 ms |
31504 KB |
Output is correct |
85 |
Correct |
148 ms |
33972 KB |
Output is correct |
86 |
Correct |
176 ms |
41268 KB |
Output is correct |
87 |
Correct |
119 ms |
41332 KB |
Output is correct |
88 |
Correct |
114 ms |
35692 KB |
Output is correct |
89 |
Correct |
129 ms |
31952 KB |
Output is correct |
90 |
Correct |
195 ms |
35300 KB |
Output is correct |
91 |
Correct |
149 ms |
35132 KB |
Output is correct |
92 |
Correct |
193 ms |
35488 KB |
Output is correct |
93 |
Correct |
172 ms |
35692 KB |
Output is correct |
94 |
Correct |
156 ms |
34876 KB |
Output is correct |
95 |
Correct |
105 ms |
39316 KB |
Output is correct |
96 |
Correct |
81 ms |
36816 KB |
Output is correct |
97 |
Correct |
90 ms |
25724 KB |
Output is correct |
98 |
Correct |
152 ms |
32600 KB |
Output is correct |
99 |
Correct |
131 ms |
31984 KB |
Output is correct |
100 |
Correct |
35 ms |
16332 KB |
Output is correct |
101 |
Correct |
160 ms |
35144 KB |
Output is correct |
102 |
Correct |
136 ms |
31464 KB |
Output is correct |
103 |
Correct |
156 ms |
33264 KB |
Output is correct |
104 |
Correct |
152 ms |
35152 KB |
Output is correct |