#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
void init(ll n, vll& par) {
for (ll i = 0; i < n; i++)
{
par[i] = i;
}
}
ll find(ll a, vll& par) {
if (par[a] == a)
return a;
return par[a] = find(par[a], par);
}
int main() {
ll n, m;
cin >> n >> m;
vll num(n);
for (auto& i : num)
{
cin >> i;
}
vector<vll> nei(n);
for (int i = 0; i < m; i++)
{
ll a, b;
cin >> a >> b;
nei[a - 1].push_back(b - 1);
nei[b - 1].push_back(a - 1);
}
vll par(n);
vll overtake(n);
init(n, par);
init(n, overtake);
vector<pair<ll, ll>> pairs;
vll visited(n, 0);
for (int i = 0; i < n; i++)
{
pairs.push_back({ num[i],i });
}
sort(pairs.begin(), pairs.end());
for (int i = 0; i < n; i++)
{
ll v = pairs[i].second;
ll cost = pairs[i].first;
visited[v] = 1;
for (int u : nei[v])
{
if (!visited[u])
continue;
u = find(u, par);
if (u == v)
continue;
num[v] += num[u];
par[u] = v;
if (num[u] >= cost)
overtake[u] = v;
}
}
ll v = pairs[n - 1].second;
for (int i = 0; i < n; i++)
{
if (find(i, overtake) == v)
cout << 1;
else
cout << 0;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
556 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
568 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
177 ms |
26552 KB |
Output is correct |
4 |
Correct |
142 ms |
26808 KB |
Output is correct |
5 |
Correct |
170 ms |
25792 KB |
Output is correct |
6 |
Correct |
175 ms |
26560 KB |
Output is correct |
7 |
Correct |
167 ms |
26564 KB |
Output is correct |
8 |
Correct |
200 ms |
27836 KB |
Output is correct |
9 |
Correct |
170 ms |
27584 KB |
Output is correct |
10 |
Correct |
131 ms |
26436 KB |
Output is correct |
11 |
Correct |
151 ms |
27708 KB |
Output is correct |
12 |
Correct |
153 ms |
25280 KB |
Output is correct |
13 |
Correct |
139 ms |
25648 KB |
Output is correct |
14 |
Correct |
130 ms |
25776 KB |
Output is correct |
15 |
Correct |
155 ms |
25536 KB |
Output is correct |
16 |
Correct |
122 ms |
24776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
175 ms |
25796 KB |
Output is correct |
3 |
Correct |
205 ms |
25688 KB |
Output is correct |
4 |
Correct |
166 ms |
26808 KB |
Output is correct |
5 |
Correct |
132 ms |
25048 KB |
Output is correct |
6 |
Correct |
170 ms |
25580 KB |
Output is correct |
7 |
Correct |
166 ms |
25532 KB |
Output is correct |
8 |
Correct |
179 ms |
25540 KB |
Output is correct |
9 |
Correct |
140 ms |
24676 KB |
Output is correct |
10 |
Correct |
173 ms |
25024 KB |
Output is correct |
11 |
Correct |
156 ms |
24260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
268 ms |
26564 KB |
Output is correct |
3 |
Correct |
234 ms |
26620 KB |
Output is correct |
4 |
Correct |
239 ms |
26556 KB |
Output is correct |
5 |
Correct |
216 ms |
26560 KB |
Output is correct |
6 |
Correct |
207 ms |
25656 KB |
Output is correct |
7 |
Correct |
185 ms |
27528 KB |
Output is correct |
8 |
Correct |
131 ms |
26304 KB |
Output is correct |
9 |
Correct |
175 ms |
16044 KB |
Output is correct |
10 |
Correct |
159 ms |
25448 KB |
Output is correct |
11 |
Correct |
179 ms |
24256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
556 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
568 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
177 ms |
26552 KB |
Output is correct |
18 |
Correct |
142 ms |
26808 KB |
Output is correct |
19 |
Correct |
170 ms |
25792 KB |
Output is correct |
20 |
Correct |
175 ms |
26560 KB |
Output is correct |
21 |
Correct |
167 ms |
26564 KB |
Output is correct |
22 |
Correct |
200 ms |
27836 KB |
Output is correct |
23 |
Correct |
170 ms |
27584 KB |
Output is correct |
24 |
Correct |
131 ms |
26436 KB |
Output is correct |
25 |
Correct |
151 ms |
27708 KB |
Output is correct |
26 |
Correct |
153 ms |
25280 KB |
Output is correct |
27 |
Correct |
139 ms |
25648 KB |
Output is correct |
28 |
Correct |
130 ms |
25776 KB |
Output is correct |
29 |
Correct |
155 ms |
25536 KB |
Output is correct |
30 |
Correct |
122 ms |
24776 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
175 ms |
25796 KB |
Output is correct |
33 |
Correct |
205 ms |
25688 KB |
Output is correct |
34 |
Correct |
166 ms |
26808 KB |
Output is correct |
35 |
Correct |
132 ms |
25048 KB |
Output is correct |
36 |
Correct |
170 ms |
25580 KB |
Output is correct |
37 |
Correct |
166 ms |
25532 KB |
Output is correct |
38 |
Correct |
179 ms |
25540 KB |
Output is correct |
39 |
Correct |
140 ms |
24676 KB |
Output is correct |
40 |
Correct |
173 ms |
25024 KB |
Output is correct |
41 |
Correct |
156 ms |
24260 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
268 ms |
26564 KB |
Output is correct |
44 |
Correct |
234 ms |
26620 KB |
Output is correct |
45 |
Correct |
239 ms |
26556 KB |
Output is correct |
46 |
Correct |
216 ms |
26560 KB |
Output is correct |
47 |
Correct |
207 ms |
25656 KB |
Output is correct |
48 |
Correct |
185 ms |
27528 KB |
Output is correct |
49 |
Correct |
131 ms |
26304 KB |
Output is correct |
50 |
Correct |
175 ms |
16044 KB |
Output is correct |
51 |
Correct |
159 ms |
25448 KB |
Output is correct |
52 |
Correct |
179 ms |
24256 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
2 ms |
600 KB |
Output is correct |
57 |
Correct |
2 ms |
488 KB |
Output is correct |
58 |
Correct |
2 ms |
600 KB |
Output is correct |
59 |
Correct |
2 ms |
480 KB |
Output is correct |
60 |
Correct |
2 ms |
604 KB |
Output is correct |
61 |
Correct |
2 ms |
600 KB |
Output is correct |
62 |
Correct |
2 ms |
604 KB |
Output is correct |
63 |
Correct |
2 ms |
600 KB |
Output is correct |
64 |
Correct |
2 ms |
604 KB |
Output is correct |
65 |
Correct |
1 ms |
520 KB |
Output is correct |
66 |
Correct |
1 ms |
604 KB |
Output is correct |
67 |
Correct |
171 ms |
26620 KB |
Output is correct |
68 |
Correct |
134 ms |
26592 KB |
Output is correct |
69 |
Correct |
152 ms |
25724 KB |
Output is correct |
70 |
Correct |
166 ms |
26564 KB |
Output is correct |
71 |
Correct |
159 ms |
26564 KB |
Output is correct |
72 |
Correct |
195 ms |
28060 KB |
Output is correct |
73 |
Correct |
169 ms |
27588 KB |
Output is correct |
74 |
Correct |
133 ms |
26436 KB |
Output is correct |
75 |
Correct |
151 ms |
27604 KB |
Output is correct |
76 |
Correct |
155 ms |
25280 KB |
Output is correct |
77 |
Correct |
145 ms |
25536 KB |
Output is correct |
78 |
Correct |
134 ms |
25792 KB |
Output is correct |
79 |
Correct |
159 ms |
25696 KB |
Output is correct |
80 |
Correct |
131 ms |
24772 KB |
Output is correct |
81 |
Correct |
180 ms |
25408 KB |
Output is correct |
82 |
Correct |
189 ms |
25548 KB |
Output is correct |
83 |
Correct |
216 ms |
26812 KB |
Output is correct |
84 |
Correct |
132 ms |
24936 KB |
Output is correct |
85 |
Correct |
187 ms |
25540 KB |
Output is correct |
86 |
Correct |
183 ms |
25680 KB |
Output is correct |
87 |
Correct |
179 ms |
25524 KB |
Output is correct |
88 |
Correct |
146 ms |
25020 KB |
Output is correct |
89 |
Correct |
155 ms |
24256 KB |
Output is correct |
90 |
Correct |
178 ms |
26564 KB |
Output is correct |
91 |
Correct |
176 ms |
26404 KB |
Output is correct |
92 |
Correct |
184 ms |
26816 KB |
Output is correct |
93 |
Correct |
179 ms |
26556 KB |
Output is correct |
94 |
Correct |
169 ms |
25548 KB |
Output is correct |
95 |
Correct |
154 ms |
27556 KB |
Output is correct |
96 |
Correct |
128 ms |
26304 KB |
Output is correct |
97 |
Correct |
116 ms |
16076 KB |
Output is correct |
98 |
Correct |
154 ms |
25484 KB |
Output is correct |
99 |
Correct |
151 ms |
24240 KB |
Output is correct |
100 |
Correct |
66 ms |
6904 KB |
Output is correct |
101 |
Correct |
192 ms |
26548 KB |
Output is correct |
102 |
Correct |
182 ms |
23236 KB |
Output is correct |
103 |
Correct |
178 ms |
23940 KB |
Output is correct |
104 |
Correct |
212 ms |
26416 KB |
Output is correct |