#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
vector<pair<int, int>> e;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
e.emplace_back(u, v);
}
sort(e.begin(), e.end(), [&](const pair<int, int> &a, const pair<int, int> &b) {
return max(s[a.first], s[a.second]) < max(s[b.first], s[b.second]);
});
vector<int> p(n), mx(n);
vector<i64> sum(n);
vector<vector<int>> win(n);
for (int i = 0; i < n; i++) {
p[i] = i;
mx[i] = sum[i] = s[i];
win[i] = {i};
}
auto leader = [&](int u) {
while (u != p[u]) u = p[u] = p[p[u]];
return u;
};
auto unite = [&](int u, int v) {
u = leader(u);
v = leader(v);
if (u == v)
return;
if (sum[u] < mx[v])
win[u].clear();
if (sum[v] < mx[u])
win[v].clear();
if (win[u].size() < win[v].size())
swap(u, v);
win[u].insert(win[u].end(), win[v].begin(), win[v].end());
win[v].clear();
sum[u] += sum[v];
mx[u] = max(mx[u], mx[v]);
p[v] = u;
};
for (auto [u, v] : e) {
unite(u, v);
}
vector<int> ans(n);
for (int u : win[leader(0)]) {
ans[u] = 1;
}
for (int i = 0; i < n; i++) {
cout << ans[i];
}
cout << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
476 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
120 ms |
19184 KB |
Output is correct |
4 |
Correct |
121 ms |
25196 KB |
Output is correct |
5 |
Correct |
110 ms |
20696 KB |
Output is correct |
6 |
Correct |
111 ms |
21412 KB |
Output is correct |
7 |
Correct |
123 ms |
21360 KB |
Output is correct |
8 |
Correct |
146 ms |
22684 KB |
Output is correct |
9 |
Correct |
103 ms |
22220 KB |
Output is correct |
10 |
Correct |
83 ms |
17736 KB |
Output is correct |
11 |
Correct |
111 ms |
18776 KB |
Output is correct |
12 |
Correct |
118 ms |
19568 KB |
Output is correct |
13 |
Correct |
129 ms |
25284 KB |
Output is correct |
14 |
Correct |
135 ms |
24728 KB |
Output is correct |
15 |
Correct |
122 ms |
18716 KB |
Output is correct |
16 |
Correct |
76 ms |
18500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
129 ms |
21880 KB |
Output is correct |
3 |
Correct |
138 ms |
21604 KB |
Output is correct |
4 |
Correct |
140 ms |
25240 KB |
Output is correct |
5 |
Correct |
143 ms |
25460 KB |
Output is correct |
6 |
Correct |
138 ms |
21832 KB |
Output is correct |
7 |
Correct |
107 ms |
18672 KB |
Output is correct |
8 |
Correct |
98 ms |
18720 KB |
Output is correct |
9 |
Correct |
76 ms |
18504 KB |
Output is correct |
10 |
Correct |
126 ms |
21368 KB |
Output is correct |
11 |
Correct |
126 ms |
22604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
131 ms |
19912 KB |
Output is correct |
3 |
Correct |
117 ms |
20036 KB |
Output is correct |
4 |
Correct |
125 ms |
20936 KB |
Output is correct |
5 |
Correct |
137 ms |
21832 KB |
Output is correct |
6 |
Correct |
160 ms |
19444 KB |
Output is correct |
7 |
Correct |
100 ms |
18744 KB |
Output is correct |
8 |
Correct |
83 ms |
20928 KB |
Output is correct |
9 |
Correct |
84 ms |
10544 KB |
Output is correct |
10 |
Correct |
123 ms |
22632 KB |
Output is correct |
11 |
Correct |
109 ms |
22400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
476 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
120 ms |
19184 KB |
Output is correct |
18 |
Correct |
121 ms |
25196 KB |
Output is correct |
19 |
Correct |
110 ms |
20696 KB |
Output is correct |
20 |
Correct |
111 ms |
21412 KB |
Output is correct |
21 |
Correct |
123 ms |
21360 KB |
Output is correct |
22 |
Correct |
146 ms |
22684 KB |
Output is correct |
23 |
Correct |
103 ms |
22220 KB |
Output is correct |
24 |
Correct |
83 ms |
17736 KB |
Output is correct |
25 |
Correct |
111 ms |
18776 KB |
Output is correct |
26 |
Correct |
118 ms |
19568 KB |
Output is correct |
27 |
Correct |
129 ms |
25284 KB |
Output is correct |
28 |
Correct |
135 ms |
24728 KB |
Output is correct |
29 |
Correct |
122 ms |
18716 KB |
Output is correct |
30 |
Correct |
76 ms |
18500 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
129 ms |
21880 KB |
Output is correct |
33 |
Correct |
138 ms |
21604 KB |
Output is correct |
34 |
Correct |
140 ms |
25240 KB |
Output is correct |
35 |
Correct |
143 ms |
25460 KB |
Output is correct |
36 |
Correct |
138 ms |
21832 KB |
Output is correct |
37 |
Correct |
107 ms |
18672 KB |
Output is correct |
38 |
Correct |
98 ms |
18720 KB |
Output is correct |
39 |
Correct |
76 ms |
18504 KB |
Output is correct |
40 |
Correct |
126 ms |
21368 KB |
Output is correct |
41 |
Correct |
126 ms |
22604 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
131 ms |
19912 KB |
Output is correct |
44 |
Correct |
117 ms |
20036 KB |
Output is correct |
45 |
Correct |
125 ms |
20936 KB |
Output is correct |
46 |
Correct |
137 ms |
21832 KB |
Output is correct |
47 |
Correct |
160 ms |
19444 KB |
Output is correct |
48 |
Correct |
100 ms |
18744 KB |
Output is correct |
49 |
Correct |
83 ms |
20928 KB |
Output is correct |
50 |
Correct |
84 ms |
10544 KB |
Output is correct |
51 |
Correct |
123 ms |
22632 KB |
Output is correct |
52 |
Correct |
109 ms |
22400 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
1 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 |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
1 ms |
340 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 |
468 KB |
Output is correct |
67 |
Correct |
98 ms |
19164 KB |
Output is correct |
68 |
Correct |
118 ms |
25028 KB |
Output is correct |
69 |
Correct |
118 ms |
20648 KB |
Output is correct |
70 |
Correct |
119 ms |
21428 KB |
Output is correct |
71 |
Correct |
136 ms |
21312 KB |
Output is correct |
72 |
Correct |
128 ms |
22664 KB |
Output is correct |
73 |
Correct |
100 ms |
22260 KB |
Output is correct |
74 |
Correct |
85 ms |
17728 KB |
Output is correct |
75 |
Correct |
101 ms |
18712 KB |
Output is correct |
76 |
Correct |
151 ms |
19536 KB |
Output is correct |
77 |
Correct |
125 ms |
25352 KB |
Output is correct |
78 |
Correct |
125 ms |
24652 KB |
Output is correct |
79 |
Correct |
101 ms |
18668 KB |
Output is correct |
80 |
Correct |
78 ms |
18496 KB |
Output is correct |
81 |
Correct |
126 ms |
21924 KB |
Output is correct |
82 |
Correct |
131 ms |
21648 KB |
Output is correct |
83 |
Correct |
150 ms |
25144 KB |
Output is correct |
84 |
Correct |
124 ms |
25572 KB |
Output is correct |
85 |
Correct |
124 ms |
21860 KB |
Output is correct |
86 |
Correct |
102 ms |
18676 KB |
Output is correct |
87 |
Correct |
102 ms |
18740 KB |
Output is correct |
88 |
Correct |
114 ms |
21424 KB |
Output is correct |
89 |
Correct |
131 ms |
22568 KB |
Output is correct |
90 |
Correct |
113 ms |
19808 KB |
Output is correct |
91 |
Correct |
114 ms |
19996 KB |
Output is correct |
92 |
Correct |
125 ms |
21060 KB |
Output is correct |
93 |
Correct |
165 ms |
21832 KB |
Output is correct |
94 |
Correct |
130 ms |
19324 KB |
Output is correct |
95 |
Correct |
101 ms |
18652 KB |
Output is correct |
96 |
Correct |
87 ms |
21036 KB |
Output is correct |
97 |
Correct |
72 ms |
10564 KB |
Output is correct |
98 |
Correct |
140 ms |
22604 KB |
Output is correct |
99 |
Correct |
111 ms |
22460 KB |
Output is correct |
100 |
Correct |
46 ms |
2424 KB |
Output is correct |
101 |
Correct |
144 ms |
20224 KB |
Output is correct |
102 |
Correct |
115 ms |
15760 KB |
Output is correct |
103 |
Correct |
110 ms |
16072 KB |
Output is correct |
104 |
Correct |
122 ms |
19276 KB |
Output is correct |