#include <bits/stdc++.h>
using ll = long long;
#define pb push_back
const int N = 2e5 + 4;
int n, m, st[N], a[N], b[N], idx[N], par[N];
ll sum[N];
char ans[N];
std::vector<int> vset[N];
bool cmp(int i, int j) {
int x = std::max(st[a[i]], st[b[i]]);
int y = std::max(st[a[j]], st[b[j]]);
return x < y;
}
int gr(int v) {
std::stack<int> s;
s.push(v);
while (par[s.top()] != s.top()) {
s.push(par[s.top()]);
}
int ret = s.top();
while (!s.empty()) {
par[s.top()] = ret;
s.pop();
}
return ret;
}
void mrg(int v, int u, int w) {
v = gr(v);
u = gr(u);
if (v == u) {
return;
}
if (sum[v] > sum[u]) {
std::swap(v, u);
}
bool b = sum[v] < w;
for (int x : vset[v]) {
vset[u].pb(x);
if (b) {
ans[x] = '0';
}
}
sum[u] += sum[v];
par[v] = u;
return;
}
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::cin >> n >> m;
for (int i = 0; i < n; ++i) {
std::cin >> sum[i];
st[i] = sum[i];
vset[i].pb(i);
ans[i] = '1';
par[i] = i;
}
for (int i = 0; i < m; ++i) {
std::cin >> a[i] >> b[i];
--a[i], --b[i];
idx[i] = i;
}
std::sort(idx, idx + m, cmp);
for (int i = 0; i < m; ++i) {
int j = idx[i];
int w = std::max(st[a[j]], st[b[j]]);
mrg(a[j], b[j], w);
}
for (int i = 0; i < n; ++i) {
std::cout << ans[i];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8792 KB |
Output is correct |
5 |
Correct |
3 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
3 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8792 KB |
Output is correct |
9 |
Correct |
3 ms |
8792 KB |
Output is correct |
10 |
Correct |
3 ms |
8796 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
3 ms |
9048 KB |
Output is correct |
13 |
Correct |
2 ms |
8792 KB |
Output is correct |
14 |
Correct |
3 ms |
8792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8792 KB |
Output is correct |
3 |
Correct |
111 ms |
22944 KB |
Output is correct |
4 |
Correct |
113 ms |
31168 KB |
Output is correct |
5 |
Correct |
137 ms |
26352 KB |
Output is correct |
6 |
Correct |
130 ms |
26688 KB |
Output is correct |
7 |
Correct |
135 ms |
26868 KB |
Output is correct |
8 |
Correct |
118 ms |
26356 KB |
Output is correct |
9 |
Correct |
117 ms |
31296 KB |
Output is correct |
10 |
Correct |
94 ms |
21784 KB |
Output is correct |
11 |
Correct |
96 ms |
21452 KB |
Output is correct |
12 |
Correct |
116 ms |
26308 KB |
Output is correct |
13 |
Correct |
112 ms |
28992 KB |
Output is correct |
14 |
Correct |
111 ms |
30660 KB |
Output is correct |
15 |
Correct |
110 ms |
22468 KB |
Output is correct |
16 |
Correct |
70 ms |
21656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
144 ms |
28992 KB |
Output is correct |
3 |
Correct |
147 ms |
28736 KB |
Output is correct |
4 |
Correct |
127 ms |
29036 KB |
Output is correct |
5 |
Correct |
114 ms |
28740 KB |
Output is correct |
6 |
Correct |
161 ms |
28864 KB |
Output is correct |
7 |
Correct |
105 ms |
22472 KB |
Output is correct |
8 |
Correct |
103 ms |
22472 KB |
Output is correct |
9 |
Correct |
73 ms |
21968 KB |
Output is correct |
10 |
Correct |
114 ms |
28484 KB |
Output is correct |
11 |
Correct |
117 ms |
30660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
137 ms |
24596 KB |
Output is correct |
3 |
Correct |
137 ms |
25544 KB |
Output is correct |
4 |
Correct |
138 ms |
26532 KB |
Output is correct |
5 |
Correct |
136 ms |
26056 KB |
Output is correct |
6 |
Correct |
111 ms |
23752 KB |
Output is correct |
7 |
Correct |
97 ms |
22608 KB |
Output is correct |
8 |
Correct |
79 ms |
23624 KB |
Output is correct |
9 |
Correct |
74 ms |
17612 KB |
Output is correct |
10 |
Correct |
113 ms |
26564 KB |
Output is correct |
11 |
Correct |
120 ms |
31040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8792 KB |
Output is correct |
5 |
Correct |
3 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
3 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8792 KB |
Output is correct |
9 |
Correct |
3 ms |
8792 KB |
Output is correct |
10 |
Correct |
3 ms |
8796 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
3 ms |
9048 KB |
Output is correct |
13 |
Correct |
2 ms |
8792 KB |
Output is correct |
14 |
Correct |
3 ms |
8792 KB |
Output is correct |
15 |
Correct |
3 ms |
8792 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
111 ms |
22944 KB |
Output is correct |
18 |
Correct |
113 ms |
31168 KB |
Output is correct |
19 |
Correct |
137 ms |
26352 KB |
Output is correct |
20 |
Correct |
130 ms |
26688 KB |
Output is correct |
21 |
Correct |
135 ms |
26868 KB |
Output is correct |
22 |
Correct |
118 ms |
26356 KB |
Output is correct |
23 |
Correct |
117 ms |
31296 KB |
Output is correct |
24 |
Correct |
94 ms |
21784 KB |
Output is correct |
25 |
Correct |
96 ms |
21452 KB |
Output is correct |
26 |
Correct |
116 ms |
26308 KB |
Output is correct |
27 |
Correct |
112 ms |
28992 KB |
Output is correct |
28 |
Correct |
111 ms |
30660 KB |
Output is correct |
29 |
Correct |
110 ms |
22468 KB |
Output is correct |
30 |
Correct |
70 ms |
21656 KB |
Output is correct |
31 |
Correct |
2 ms |
8792 KB |
Output is correct |
32 |
Correct |
144 ms |
28992 KB |
Output is correct |
33 |
Correct |
147 ms |
28736 KB |
Output is correct |
34 |
Correct |
127 ms |
29036 KB |
Output is correct |
35 |
Correct |
114 ms |
28740 KB |
Output is correct |
36 |
Correct |
161 ms |
28864 KB |
Output is correct |
37 |
Correct |
105 ms |
22472 KB |
Output is correct |
38 |
Correct |
103 ms |
22472 KB |
Output is correct |
39 |
Correct |
73 ms |
21968 KB |
Output is correct |
40 |
Correct |
114 ms |
28484 KB |
Output is correct |
41 |
Correct |
117 ms |
30660 KB |
Output is correct |
42 |
Correct |
2 ms |
8792 KB |
Output is correct |
43 |
Correct |
137 ms |
24596 KB |
Output is correct |
44 |
Correct |
137 ms |
25544 KB |
Output is correct |
45 |
Correct |
138 ms |
26532 KB |
Output is correct |
46 |
Correct |
136 ms |
26056 KB |
Output is correct |
47 |
Correct |
111 ms |
23752 KB |
Output is correct |
48 |
Correct |
97 ms |
22608 KB |
Output is correct |
49 |
Correct |
79 ms |
23624 KB |
Output is correct |
50 |
Correct |
74 ms |
17612 KB |
Output is correct |
51 |
Correct |
113 ms |
26564 KB |
Output is correct |
52 |
Correct |
120 ms |
31040 KB |
Output is correct |
53 |
Correct |
2 ms |
8784 KB |
Output is correct |
54 |
Correct |
2 ms |
8792 KB |
Output is correct |
55 |
Correct |
2 ms |
8796 KB |
Output is correct |
56 |
Correct |
2 ms |
8792 KB |
Output is correct |
57 |
Correct |
3 ms |
8792 KB |
Output is correct |
58 |
Correct |
3 ms |
8792 KB |
Output is correct |
59 |
Correct |
2 ms |
8792 KB |
Output is correct |
60 |
Correct |
3 ms |
8792 KB |
Output is correct |
61 |
Correct |
2 ms |
8796 KB |
Output is correct |
62 |
Correct |
3 ms |
8792 KB |
Output is correct |
63 |
Correct |
3 ms |
8792 KB |
Output is correct |
64 |
Correct |
2 ms |
8792 KB |
Output is correct |
65 |
Correct |
3 ms |
8792 KB |
Output is correct |
66 |
Correct |
3 ms |
8792 KB |
Output is correct |
67 |
Correct |
105 ms |
22984 KB |
Output is correct |
68 |
Correct |
106 ms |
31168 KB |
Output is correct |
69 |
Correct |
126 ms |
26304 KB |
Output is correct |
70 |
Correct |
128 ms |
26688 KB |
Output is correct |
71 |
Correct |
130 ms |
27076 KB |
Output is correct |
72 |
Correct |
132 ms |
26184 KB |
Output is correct |
73 |
Correct |
124 ms |
31428 KB |
Output is correct |
74 |
Correct |
108 ms |
21704 KB |
Output is correct |
75 |
Correct |
90 ms |
21448 KB |
Output is correct |
76 |
Correct |
108 ms |
26344 KB |
Output is correct |
77 |
Correct |
109 ms |
28972 KB |
Output is correct |
78 |
Correct |
117 ms |
30536 KB |
Output is correct |
79 |
Correct |
100 ms |
22452 KB |
Output is correct |
80 |
Correct |
71 ms |
21712 KB |
Output is correct |
81 |
Correct |
149 ms |
29252 KB |
Output is correct |
82 |
Correct |
141 ms |
28676 KB |
Output is correct |
83 |
Correct |
116 ms |
28968 KB |
Output is correct |
84 |
Correct |
117 ms |
28992 KB |
Output is correct |
85 |
Correct |
140 ms |
28864 KB |
Output is correct |
86 |
Correct |
109 ms |
22728 KB |
Output is correct |
87 |
Correct |
106 ms |
22476 KB |
Output is correct |
88 |
Correct |
135 ms |
28524 KB |
Output is correct |
89 |
Correct |
118 ms |
30916 KB |
Output is correct |
90 |
Correct |
129 ms |
24480 KB |
Output is correct |
91 |
Correct |
122 ms |
25544 KB |
Output is correct |
92 |
Correct |
126 ms |
26516 KB |
Output is correct |
93 |
Correct |
112 ms |
25628 KB |
Output is correct |
94 |
Correct |
105 ms |
23752 KB |
Output is correct |
95 |
Correct |
101 ms |
22472 KB |
Output is correct |
96 |
Correct |
79 ms |
23624 KB |
Output is correct |
97 |
Correct |
73 ms |
17556 KB |
Output is correct |
98 |
Correct |
102 ms |
26424 KB |
Output is correct |
99 |
Correct |
111 ms |
31136 KB |
Output is correct |
100 |
Correct |
62 ms |
11856 KB |
Output is correct |
101 |
Correct |
156 ms |
25772 KB |
Output is correct |
102 |
Correct |
94 ms |
21412 KB |
Output is correct |
103 |
Correct |
124 ms |
21704 KB |
Output is correct |
104 |
Correct |
147 ms |
24088 KB |
Output is correct |