#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
vector<int> dsu[2]; // biggest in group, discard?, sum of popularity
inline int boss(int u, bool b){
int &bs = dsu[b][u];
if(bs==u) return u;
return bs = boss(bs, b);
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
fill(dsu, dsu+2, vector<int>(n+1));
dsu[1][0] = 0;
vector<pair<ll, int>> s(n+1);
for(int i=1; i<=n; i++){
cin >> s[i].F;
s[i].S = i;
}
vector<vector<int>> e(n+1);
while(m--){
int a, b;
cin >> a >> b;
if(s[a]<s[b]) swap(a, b);
e[a].push_back(b);
}
s[0] = {INT32_MAX, 0};
sort(s.begin(), s.end());
s.pop_back();
vector<ll> tot(n+1);
for(const auto &[num, i] : s){
dsu[0][i] = dsu[1][i] = i;
tot[i] = num;
for(int v: e[i]){
v = boss(v, 0);
if(v==i) continue;
dsu[0][v] = i;
dsu[1][v] = (tot[v]>=num)?i:0;
tot[i] += tot[v];
}
}
for(int i=1; i<=n; i++) cout << "10"[!boss(i, 1)];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
72 ms |
15796 KB |
Output is correct |
4 |
Correct |
73 ms |
22588 KB |
Output is correct |
5 |
Correct |
72 ms |
19112 KB |
Output is correct |
6 |
Correct |
70 ms |
19784 KB |
Output is correct |
7 |
Correct |
71 ms |
19780 KB |
Output is correct |
8 |
Correct |
100 ms |
24128 KB |
Output is correct |
9 |
Correct |
63 ms |
19004 KB |
Output is correct |
10 |
Correct |
53 ms |
16960 KB |
Output is correct |
11 |
Correct |
74 ms |
23364 KB |
Output is correct |
12 |
Correct |
107 ms |
20476 KB |
Output is correct |
13 |
Correct |
81 ms |
22848 KB |
Output is correct |
14 |
Correct |
74 ms |
22592 KB |
Output is correct |
15 |
Correct |
77 ms |
22080 KB |
Output is correct |
16 |
Correct |
55 ms |
21324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
93 ms |
15636 KB |
Output is correct |
3 |
Correct |
102 ms |
20232 KB |
Output is correct |
4 |
Correct |
79 ms |
24188 KB |
Output is correct |
5 |
Correct |
72 ms |
22080 KB |
Output is correct |
6 |
Correct |
100 ms |
20036 KB |
Output is correct |
7 |
Correct |
100 ms |
22208 KB |
Output is correct |
8 |
Correct |
92 ms |
22296 KB |
Output is correct |
9 |
Correct |
57 ms |
21324 KB |
Output is correct |
10 |
Correct |
74 ms |
19524 KB |
Output is correct |
11 |
Correct |
98 ms |
18988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
97 ms |
15508 KB |
Output is correct |
3 |
Correct |
104 ms |
19788 KB |
Output is correct |
4 |
Correct |
101 ms |
20032 KB |
Output is correct |
5 |
Correct |
83 ms |
19812 KB |
Output is correct |
6 |
Correct |
77 ms |
19452 KB |
Output is correct |
7 |
Correct |
69 ms |
20804 KB |
Output is correct |
8 |
Correct |
56 ms |
22184 KB |
Output is correct |
9 |
Correct |
59 ms |
11460 KB |
Output is correct |
10 |
Correct |
83 ms |
18264 KB |
Output is correct |
11 |
Correct |
83 ms |
19004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
72 ms |
15796 KB |
Output is correct |
18 |
Correct |
73 ms |
22588 KB |
Output is correct |
19 |
Correct |
72 ms |
19112 KB |
Output is correct |
20 |
Correct |
70 ms |
19784 KB |
Output is correct |
21 |
Correct |
71 ms |
19780 KB |
Output is correct |
22 |
Correct |
100 ms |
24128 KB |
Output is correct |
23 |
Correct |
63 ms |
19004 KB |
Output is correct |
24 |
Correct |
53 ms |
16960 KB |
Output is correct |
25 |
Correct |
74 ms |
23364 KB |
Output is correct |
26 |
Correct |
107 ms |
20476 KB |
Output is correct |
27 |
Correct |
81 ms |
22848 KB |
Output is correct |
28 |
Correct |
74 ms |
22592 KB |
Output is correct |
29 |
Correct |
77 ms |
22080 KB |
Output is correct |
30 |
Correct |
55 ms |
21324 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
93 ms |
15636 KB |
Output is correct |
33 |
Correct |
102 ms |
20232 KB |
Output is correct |
34 |
Correct |
79 ms |
24188 KB |
Output is correct |
35 |
Correct |
72 ms |
22080 KB |
Output is correct |
36 |
Correct |
100 ms |
20036 KB |
Output is correct |
37 |
Correct |
100 ms |
22208 KB |
Output is correct |
38 |
Correct |
92 ms |
22296 KB |
Output is correct |
39 |
Correct |
57 ms |
21324 KB |
Output is correct |
40 |
Correct |
74 ms |
19524 KB |
Output is correct |
41 |
Correct |
98 ms |
18988 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
97 ms |
15508 KB |
Output is correct |
44 |
Correct |
104 ms |
19788 KB |
Output is correct |
45 |
Correct |
101 ms |
20032 KB |
Output is correct |
46 |
Correct |
83 ms |
19812 KB |
Output is correct |
47 |
Correct |
77 ms |
19452 KB |
Output is correct |
48 |
Correct |
69 ms |
20804 KB |
Output is correct |
49 |
Correct |
56 ms |
22184 KB |
Output is correct |
50 |
Correct |
59 ms |
11460 KB |
Output is correct |
51 |
Correct |
83 ms |
18264 KB |
Output is correct |
52 |
Correct |
83 ms |
19004 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
59 |
Correct |
1 ms |
600 KB |
Output is correct |
60 |
Correct |
1 ms |
600 KB |
Output is correct |
61 |
Correct |
1 ms |
604 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
604 KB |
Output is correct |
65 |
Correct |
1 ms |
604 KB |
Output is correct |
66 |
Correct |
1 ms |
604 KB |
Output is correct |
67 |
Correct |
81 ms |
20264 KB |
Output is correct |
68 |
Correct |
75 ms |
22592 KB |
Output is correct |
69 |
Correct |
70 ms |
19088 KB |
Output is correct |
70 |
Correct |
73 ms |
20036 KB |
Output is correct |
71 |
Correct |
86 ms |
19908 KB |
Output is correct |
72 |
Correct |
113 ms |
24124 KB |
Output is correct |
73 |
Correct |
65 ms |
19012 KB |
Output is correct |
74 |
Correct |
50 ms |
16964 KB |
Output is correct |
75 |
Correct |
74 ms |
23364 KB |
Output is correct |
76 |
Correct |
78 ms |
20284 KB |
Output is correct |
77 |
Correct |
91 ms |
22796 KB |
Output is correct |
78 |
Correct |
72 ms |
22588 KB |
Output is correct |
79 |
Correct |
70 ms |
22080 KB |
Output is correct |
80 |
Correct |
56 ms |
21324 KB |
Output is correct |
81 |
Correct |
87 ms |
20088 KB |
Output is correct |
82 |
Correct |
87 ms |
20032 KB |
Output is correct |
83 |
Correct |
93 ms |
24636 KB |
Output is correct |
84 |
Correct |
74 ms |
22072 KB |
Output is correct |
85 |
Correct |
86 ms |
20028 KB |
Output is correct |
86 |
Correct |
90 ms |
22336 KB |
Output is correct |
87 |
Correct |
91 ms |
22340 KB |
Output is correct |
88 |
Correct |
71 ms |
19324 KB |
Output is correct |
89 |
Correct |
84 ms |
19004 KB |
Output is correct |
90 |
Correct |
98 ms |
20040 KB |
Output is correct |
91 |
Correct |
104 ms |
19784 KB |
Output is correct |
92 |
Correct |
114 ms |
20028 KB |
Output is correct |
93 |
Correct |
87 ms |
19780 KB |
Output is correct |
94 |
Correct |
81 ms |
19292 KB |
Output is correct |
95 |
Correct |
69 ms |
20804 KB |
Output is correct |
96 |
Correct |
60 ms |
22024 KB |
Output is correct |
97 |
Correct |
60 ms |
11336 KB |
Output is correct |
98 |
Correct |
81 ms |
18240 KB |
Output is correct |
99 |
Correct |
84 ms |
19116 KB |
Output is correct |
100 |
Correct |
31 ms |
3924 KB |
Output is correct |
101 |
Correct |
109 ms |
19904 KB |
Output is correct |
102 |
Correct |
73 ms |
16880 KB |
Output is correct |
103 |
Correct |
88 ms |
17604 KB |
Output is correct |
104 |
Correct |
100 ms |
19624 KB |
Output is correct |