#include <bits/stdc++.h>
using namespace std;
// #undef _GLIBCXX_DEBUG // disable run-time bound checking, etc
// #pragma GCC optimize("Ofast,inline") // Ofast = O3,fast-math,allow-store-data-races,no-protect-parens
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("bmi,bmi2,lzcnt,popcnt") // bit manipulation
// #pragma GCC target("movbe") // byte swap
// #pragma GCC target("aes,pclmul,rdrnd") // encryption
// #pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2") // SIMD
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
// template<class T>using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// template<class T>using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long
#define INF (ll)1e9+7
#define fo(i, n) for(int i=0;i<((ll)n);i++)
#define deb(x) cout << #x << " = " << x << endl;
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LSOne(S) ((S) & (-S))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
inline int readint(){ int v = 0; char c; while((c = getchar()) != EOF && c != ' ' && c != '\n'){ v *= 10; v += c - '0'; } return v; }
inline int readintsigned() { int v = 0; int sign = 1; char c = getchar(); if (c == '-') { sign = -1; } else { v += c - '0'; } while ((c = getchar()) != EOF && c != ' ' && c != '\n') { v *= 10; v += c - '0'; } return v * sign; }
inline string readstring() { string s; char c; while ((c = getchar()) != EOF && c != '\n' && c != ' ') { s.push_back(c); } return s; }
template <class result_t=std::chrono::milliseconds,class clock_t=std::chrono::steady_clock,class duration_t = std::chrono::milliseconds>
auto since(std::chrono::time_point<clock_t, duration_t> const& start){return std::chrono::duration_cast<result_t>(clock_t::now() - start);}
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vpii> vvpii;
typedef vector<vpl> vvpl;
ll n, m, val, from, to, w;
vl population;
vvl canAchieve;
vvl adj(200001);
struct UnionFind{
int n;
vl p, siz;
UnionFind(int n) : n(n){
p.assign(n, -1);
siz.assign(n, 1);
fo(i, n)p[i] = i;
}
int find(int x){
if(p[x] == x) return x;
return p[x] = find(p[x]);
}
void unite(int a, int b){
a = find(a);
b = find(b);
if(siz[b] > siz[a]) {
swap(a, b);
swap(canAchieve[a], canAchieve[b]);
}
siz[a]+=siz[b];
population[a]+=population[b];
p[b] = a;
}
};
int main() {
// cout << fixed << setprecision(20);
// auto start = std::chrono::steady_clock::now(); // since(start).count()
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
vpl popSort;
fo(i, n){
cin >> val;
population.pb(val);
popSort.pb({val, i});
canAchieve.pb({i});
}
sort(all(popSort));
pii biggestPop = popSort[n-1];
fo(i, m){
cin >> from >> to;
adj[--from].pb(--to);
adj[to].pb(from);
}
vi ans(n, 0);
UnionFind uf(n);
vi seen(n, 0);
for(auto start : popSort){
ll currentPop = population[start.S];
for(auto v : adj[start.S]){
if(!seen[v]) continue;
from = uf.find(start.S);
v = uf.find(v);
if(from == v) continue;
if(currentPop <= population[v]){
if(canAchieve[from].size() < canAchieve[v].size()) swap(canAchieve[from], canAchieve[v]);
fo(i, canAchieve[v].size()) canAchieve[from].pb(canAchieve[v][i]);
}
uf.unite(from, v);
}
seen[start.S] = 1;
}
fo(i, canAchieve[uf.find(biggestPop.S)].size()) ans[canAchieve[uf.find(biggestPop.S)][i]] = 1;
fo(i, n) cout << ans[i];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5332 KB |
Output is correct |
5 |
Correct |
4 ms |
5292 KB |
Output is correct |
6 |
Correct |
3 ms |
5332 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5332 KB |
Output is correct |
10 |
Correct |
3 ms |
5332 KB |
Output is correct |
11 |
Correct |
4 ms |
5348 KB |
Output is correct |
12 |
Correct |
3 ms |
5332 KB |
Output is correct |
13 |
Correct |
3 ms |
5332 KB |
Output is correct |
14 |
Correct |
4 ms |
5332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
133 ms |
40332 KB |
Output is correct |
4 |
Correct |
117 ms |
39340 KB |
Output is correct |
5 |
Correct |
137 ms |
42588 KB |
Output is correct |
6 |
Correct |
144 ms |
43932 KB |
Output is correct |
7 |
Correct |
142 ms |
44048 KB |
Output is correct |
8 |
Correct |
132 ms |
40844 KB |
Output is correct |
9 |
Correct |
131 ms |
47276 KB |
Output is correct |
10 |
Correct |
88 ms |
36980 KB |
Output is correct |
11 |
Correct |
120 ms |
40332 KB |
Output is correct |
12 |
Correct |
146 ms |
38176 KB |
Output is correct |
13 |
Correct |
115 ms |
38284 KB |
Output is correct |
14 |
Correct |
109 ms |
38300 KB |
Output is correct |
15 |
Correct |
117 ms |
39792 KB |
Output is correct |
16 |
Correct |
88 ms |
38796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
177 ms |
44308 KB |
Output is correct |
3 |
Correct |
170 ms |
44640 KB |
Output is correct |
4 |
Correct |
130 ms |
39892 KB |
Output is correct |
5 |
Correct |
110 ms |
37780 KB |
Output is correct |
6 |
Correct |
189 ms |
44284 KB |
Output is correct |
7 |
Correct |
127 ms |
39872 KB |
Output is correct |
8 |
Correct |
133 ms |
39872 KB |
Output is correct |
9 |
Correct |
87 ms |
38896 KB |
Output is correct |
10 |
Correct |
111 ms |
37384 KB |
Output is correct |
11 |
Correct |
133 ms |
38016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
178 ms |
40932 KB |
Output is correct |
3 |
Correct |
186 ms |
41636 KB |
Output is correct |
4 |
Correct |
180 ms |
43952 KB |
Output is correct |
5 |
Correct |
173 ms |
46344 KB |
Output is correct |
6 |
Correct |
154 ms |
41736 KB |
Output is correct |
7 |
Correct |
126 ms |
41388 KB |
Output is correct |
8 |
Correct |
89 ms |
39288 KB |
Output is correct |
9 |
Correct |
86 ms |
24992 KB |
Output is correct |
10 |
Correct |
148 ms |
46716 KB |
Output is correct |
11 |
Correct |
137 ms |
38036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5332 KB |
Output is correct |
5 |
Correct |
4 ms |
5292 KB |
Output is correct |
6 |
Correct |
3 ms |
5332 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5332 KB |
Output is correct |
10 |
Correct |
3 ms |
5332 KB |
Output is correct |
11 |
Correct |
4 ms |
5348 KB |
Output is correct |
12 |
Correct |
3 ms |
5332 KB |
Output is correct |
13 |
Correct |
3 ms |
5332 KB |
Output is correct |
14 |
Correct |
4 ms |
5332 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
133 ms |
40332 KB |
Output is correct |
18 |
Correct |
117 ms |
39340 KB |
Output is correct |
19 |
Correct |
137 ms |
42588 KB |
Output is correct |
20 |
Correct |
144 ms |
43932 KB |
Output is correct |
21 |
Correct |
142 ms |
44048 KB |
Output is correct |
22 |
Correct |
132 ms |
40844 KB |
Output is correct |
23 |
Correct |
131 ms |
47276 KB |
Output is correct |
24 |
Correct |
88 ms |
36980 KB |
Output is correct |
25 |
Correct |
120 ms |
40332 KB |
Output is correct |
26 |
Correct |
146 ms |
38176 KB |
Output is correct |
27 |
Correct |
115 ms |
38284 KB |
Output is correct |
28 |
Correct |
109 ms |
38300 KB |
Output is correct |
29 |
Correct |
117 ms |
39792 KB |
Output is correct |
30 |
Correct |
88 ms |
38796 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
177 ms |
44308 KB |
Output is correct |
33 |
Correct |
170 ms |
44640 KB |
Output is correct |
34 |
Correct |
130 ms |
39892 KB |
Output is correct |
35 |
Correct |
110 ms |
37780 KB |
Output is correct |
36 |
Correct |
189 ms |
44284 KB |
Output is correct |
37 |
Correct |
127 ms |
39872 KB |
Output is correct |
38 |
Correct |
133 ms |
39872 KB |
Output is correct |
39 |
Correct |
87 ms |
38896 KB |
Output is correct |
40 |
Correct |
111 ms |
37384 KB |
Output is correct |
41 |
Correct |
133 ms |
38016 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
178 ms |
40932 KB |
Output is correct |
44 |
Correct |
186 ms |
41636 KB |
Output is correct |
45 |
Correct |
180 ms |
43952 KB |
Output is correct |
46 |
Correct |
173 ms |
46344 KB |
Output is correct |
47 |
Correct |
154 ms |
41736 KB |
Output is correct |
48 |
Correct |
126 ms |
41388 KB |
Output is correct |
49 |
Correct |
89 ms |
39288 KB |
Output is correct |
50 |
Correct |
86 ms |
24992 KB |
Output is correct |
51 |
Correct |
148 ms |
46716 KB |
Output is correct |
52 |
Correct |
137 ms |
38036 KB |
Output is correct |
53 |
Correct |
2 ms |
4948 KB |
Output is correct |
54 |
Correct |
2 ms |
4948 KB |
Output is correct |
55 |
Correct |
2 ms |
4996 KB |
Output is correct |
56 |
Correct |
4 ms |
5304 KB |
Output is correct |
57 |
Correct |
4 ms |
5332 KB |
Output is correct |
58 |
Correct |
3 ms |
5332 KB |
Output is correct |
59 |
Correct |
3 ms |
5220 KB |
Output is correct |
60 |
Correct |
3 ms |
5204 KB |
Output is correct |
61 |
Correct |
3 ms |
5292 KB |
Output is correct |
62 |
Correct |
3 ms |
5396 KB |
Output is correct |
63 |
Correct |
3 ms |
5332 KB |
Output is correct |
64 |
Correct |
4 ms |
5332 KB |
Output is correct |
65 |
Correct |
3 ms |
5332 KB |
Output is correct |
66 |
Correct |
3 ms |
5300 KB |
Output is correct |
67 |
Correct |
120 ms |
40332 KB |
Output is correct |
68 |
Correct |
120 ms |
39412 KB |
Output is correct |
69 |
Correct |
142 ms |
42508 KB |
Output is correct |
70 |
Correct |
142 ms |
43940 KB |
Output is correct |
71 |
Correct |
150 ms |
44020 KB |
Output is correct |
72 |
Correct |
128 ms |
41020 KB |
Output is correct |
73 |
Correct |
125 ms |
47384 KB |
Output is correct |
74 |
Correct |
87 ms |
36928 KB |
Output is correct |
75 |
Correct |
117 ms |
40460 KB |
Output is correct |
76 |
Correct |
141 ms |
38172 KB |
Output is correct |
77 |
Correct |
115 ms |
38292 KB |
Output is correct |
78 |
Correct |
120 ms |
38292 KB |
Output is correct |
79 |
Correct |
114 ms |
39880 KB |
Output is correct |
80 |
Correct |
88 ms |
38836 KB |
Output is correct |
81 |
Correct |
170 ms |
44308 KB |
Output is correct |
82 |
Correct |
165 ms |
44624 KB |
Output is correct |
83 |
Correct |
127 ms |
39936 KB |
Output is correct |
84 |
Correct |
109 ms |
37832 KB |
Output is correct |
85 |
Correct |
182 ms |
44304 KB |
Output is correct |
86 |
Correct |
126 ms |
39944 KB |
Output is correct |
87 |
Correct |
128 ms |
39848 KB |
Output is correct |
88 |
Correct |
116 ms |
37356 KB |
Output is correct |
89 |
Correct |
133 ms |
38000 KB |
Output is correct |
90 |
Correct |
168 ms |
41004 KB |
Output is correct |
91 |
Correct |
169 ms |
41676 KB |
Output is correct |
92 |
Correct |
179 ms |
44044 KB |
Output is correct |
93 |
Correct |
174 ms |
46392 KB |
Output is correct |
94 |
Correct |
146 ms |
41852 KB |
Output is correct |
95 |
Correct |
110 ms |
41316 KB |
Output is correct |
96 |
Correct |
98 ms |
39396 KB |
Output is correct |
97 |
Correct |
87 ms |
24976 KB |
Output is correct |
98 |
Correct |
151 ms |
46748 KB |
Output is correct |
99 |
Correct |
130 ms |
37956 KB |
Output is correct |
100 |
Correct |
33 ms |
11852 KB |
Output is correct |
101 |
Correct |
195 ms |
42412 KB |
Output is correct |
102 |
Correct |
131 ms |
35980 KB |
Output is correct |
103 |
Correct |
150 ms |
35356 KB |
Output is correct |
104 |
Correct |
175 ms |
39908 KB |
Output is correct |