#include <bits/stdc++.h>
#include <utility>
using ll = long long;
using namespace std;
#define F0R(i, n) for (ll i= 0; i < n;i++)
template<typename T>
using V = vector<T>;
using vi = V<ll>;
using vvi = V<vi>;
#define pb push_back
using pi = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define f first
#define s second
V<ll> initSum;
struct dsu {
vi par, absPar;
vi siz;
vi sum;
dsu(ll n, vi initSum) {
par.resize(n, -1);
absPar.resize(n, -1);
siz.resize(n, 1);
sum = std::move(initSum);
}
ll get(ll x) {
if (absPar[x] == -1) return x;
return absPar[x] = get(absPar[x]);
}
void combine(ll a, ll b) {
a = get(a), b = get(b);
if (a == b) return;
if (initSum[b] > initSum[a]) swap(a,b);
siz[a] += siz[b];
sum[a] += sum[b];
par[b] = a;
absPar[b] = a;
}
};
//TODO CHECK CONNECTIVITY
vvi genGraph(vi par) {
vvi g(par.size());
F0R(i, par.size()) {
if (par[i] == -1) continue;
g[par[i]].pb(i);
g[i].pb(par[i]);
}
return g;
}
V<bool> possible;
dsu* dsu;
vvi g;
void dfsPos(ll x, ll p) {
if (p == -1 || dsu->sum[x] >= initSum[p]) possible[x] = true;
else return;
for (auto child : g[x]) {
if (child == p) continue;
dfsPos(child, x);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
ll n, m; cin >> n >> m;
V<pair<ll, pi>> edges;
initSum.resize(n + 1);
F0R(i, n)
cin >> initSum[i + 1];
F0R(i, m) {
ll a, b; cin >> a>> b;
edges.pb({max(initSum[a], initSum[b]), {a, b}});
}
sort(all(edges));
dsu = new struct dsu(n + 1, initSum);
for (auto [x,pa] : edges) {
auto [a,b] = pa;
dsu->combine(a,b);
}
g = genGraph(dsu->par);
ll root = dsu->get(1);
bool pos = true;
F0R(i, n)
if (dsu->get(i + 1) != root) pos = false;
possible.resize(n + 1);
if (pos) dfsPos(root, -1);
F0R(i, n) {
cout << possible[i + 1] << "";
}
return 0;
}
Compilation message
island.cpp: In function 'vvi genGraph(vi)':
island.cpp:7:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | #define F0R(i, n) for (ll i= 0; i < n;i++)
......
53 | F0R(i, par.size()) {
| ~~~~~~~~~~~~~
island.cpp:53:5: note: in expansion of macro 'F0R'
53 | F0R(i, par.size()) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 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 |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 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 |
94 ms |
30136 KB |
Output is correct |
4 |
Correct |
96 ms |
30644 KB |
Output is correct |
5 |
Correct |
112 ms |
29964 KB |
Output is correct |
6 |
Correct |
113 ms |
30900 KB |
Output is correct |
7 |
Correct |
110 ms |
30952 KB |
Output is correct |
8 |
Correct |
126 ms |
35900 KB |
Output is correct |
9 |
Correct |
97 ms |
31412 KB |
Output is correct |
10 |
Correct |
82 ms |
30648 KB |
Output is correct |
11 |
Correct |
82 ms |
34484 KB |
Output is correct |
12 |
Correct |
97 ms |
30396 KB |
Output is correct |
13 |
Correct |
85 ms |
30904 KB |
Output is correct |
14 |
Correct |
81 ms |
31160 KB |
Output is correct |
15 |
Correct |
92 ms |
39348 KB |
Output is correct |
16 |
Correct |
75 ms |
38324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
99 ms |
26552 KB |
Output is correct |
3 |
Correct |
95 ms |
26552 KB |
Output is correct |
4 |
Correct |
93 ms |
31384 KB |
Output is correct |
5 |
Correct |
92 ms |
30648 KB |
Output is correct |
6 |
Correct |
95 ms |
31160 KB |
Output is correct |
7 |
Correct |
88 ms |
39348 KB |
Output is correct |
8 |
Correct |
93 ms |
39356 KB |
Output is correct |
9 |
Correct |
68 ms |
38268 KB |
Output is correct |
10 |
Correct |
84 ms |
33724 KB |
Output is correct |
11 |
Correct |
85 ms |
30136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
118 ms |
26952 KB |
Output is correct |
3 |
Correct |
115 ms |
31144 KB |
Output is correct |
4 |
Correct |
114 ms |
31156 KB |
Output is correct |
5 |
Correct |
110 ms |
31412 KB |
Output is correct |
6 |
Correct |
108 ms |
30720 KB |
Output is correct |
7 |
Correct |
85 ms |
35556 KB |
Output is correct |
8 |
Correct |
80 ms |
32184 KB |
Output is correct |
9 |
Correct |
74 ms |
18572 KB |
Output is correct |
10 |
Correct |
111 ms |
29876 KB |
Output is correct |
11 |
Correct |
93 ms |
30012 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 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 |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 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 |
94 ms |
30136 KB |
Output is correct |
18 |
Correct |
96 ms |
30644 KB |
Output is correct |
19 |
Correct |
112 ms |
29964 KB |
Output is correct |
20 |
Correct |
113 ms |
30900 KB |
Output is correct |
21 |
Correct |
110 ms |
30952 KB |
Output is correct |
22 |
Correct |
126 ms |
35900 KB |
Output is correct |
23 |
Correct |
97 ms |
31412 KB |
Output is correct |
24 |
Correct |
82 ms |
30648 KB |
Output is correct |
25 |
Correct |
82 ms |
34484 KB |
Output is correct |
26 |
Correct |
97 ms |
30396 KB |
Output is correct |
27 |
Correct |
85 ms |
30904 KB |
Output is correct |
28 |
Correct |
81 ms |
31160 KB |
Output is correct |
29 |
Correct |
92 ms |
39348 KB |
Output is correct |
30 |
Correct |
75 ms |
38324 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
99 ms |
26552 KB |
Output is correct |
33 |
Correct |
95 ms |
26552 KB |
Output is correct |
34 |
Correct |
93 ms |
31384 KB |
Output is correct |
35 |
Correct |
92 ms |
30648 KB |
Output is correct |
36 |
Correct |
95 ms |
31160 KB |
Output is correct |
37 |
Correct |
88 ms |
39348 KB |
Output is correct |
38 |
Correct |
93 ms |
39356 KB |
Output is correct |
39 |
Correct |
68 ms |
38268 KB |
Output is correct |
40 |
Correct |
84 ms |
33724 KB |
Output is correct |
41 |
Correct |
85 ms |
30136 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
118 ms |
26952 KB |
Output is correct |
44 |
Correct |
115 ms |
31144 KB |
Output is correct |
45 |
Correct |
114 ms |
31156 KB |
Output is correct |
46 |
Correct |
110 ms |
31412 KB |
Output is correct |
47 |
Correct |
108 ms |
30720 KB |
Output is correct |
48 |
Correct |
85 ms |
35556 KB |
Output is correct |
49 |
Correct |
80 ms |
32184 KB |
Output is correct |
50 |
Correct |
74 ms |
18572 KB |
Output is correct |
51 |
Correct |
111 ms |
29876 KB |
Output is correct |
52 |
Correct |
93 ms |
30012 KB |
Output is correct |
53 |
Correct |
0 ms |
344 KB |
Output is correct |
54 |
Correct |
0 ms |
452 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 |
604 KB |
Output is correct |
60 |
Correct |
1 ms |
520 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 |
660 KB |
Output is correct |
65 |
Correct |
1 ms |
604 KB |
Output is correct |
66 |
Correct |
1 ms |
604 KB |
Output is correct |
67 |
Correct |
98 ms |
34520 KB |
Output is correct |
68 |
Correct |
95 ms |
30524 KB |
Output is correct |
69 |
Correct |
102 ms |
29880 KB |
Output is correct |
70 |
Correct |
105 ms |
30932 KB |
Output is correct |
71 |
Correct |
112 ms |
30900 KB |
Output is correct |
72 |
Correct |
117 ms |
35916 KB |
Output is correct |
73 |
Correct |
88 ms |
31592 KB |
Output is correct |
74 |
Correct |
83 ms |
30644 KB |
Output is correct |
75 |
Correct |
89 ms |
34484 KB |
Output is correct |
76 |
Correct |
100 ms |
30392 KB |
Output is correct |
77 |
Correct |
82 ms |
31156 KB |
Output is correct |
78 |
Correct |
85 ms |
31156 KB |
Output is correct |
79 |
Correct |
97 ms |
39444 KB |
Output is correct |
80 |
Correct |
71 ms |
38324 KB |
Output is correct |
81 |
Correct |
100 ms |
30908 KB |
Output is correct |
82 |
Correct |
99 ms |
31156 KB |
Output is correct |
83 |
Correct |
109 ms |
36020 KB |
Output is correct |
84 |
Correct |
79 ms |
30552 KB |
Output is correct |
85 |
Correct |
93 ms |
31160 KB |
Output is correct |
86 |
Correct |
85 ms |
39476 KB |
Output is correct |
87 |
Correct |
88 ms |
39424 KB |
Output is correct |
88 |
Correct |
86 ms |
33720 KB |
Output is correct |
89 |
Correct |
84 ms |
30136 KB |
Output is correct |
90 |
Correct |
115 ms |
31160 KB |
Output is correct |
91 |
Correct |
119 ms |
30936 KB |
Output is correct |
92 |
Correct |
121 ms |
31160 KB |
Output is correct |
93 |
Correct |
113 ms |
31248 KB |
Output is correct |
94 |
Correct |
108 ms |
30680 KB |
Output is correct |
95 |
Correct |
87 ms |
35512 KB |
Output is correct |
96 |
Correct |
77 ms |
32348 KB |
Output is correct |
97 |
Correct |
73 ms |
18612 KB |
Output is correct |
98 |
Correct |
99 ms |
29876 KB |
Output is correct |
99 |
Correct |
91 ms |
30192 KB |
Output is correct |
100 |
Correct |
47 ms |
8140 KB |
Output is correct |
101 |
Correct |
122 ms |
31160 KB |
Output is correct |
102 |
Correct |
101 ms |
27340 KB |
Output is correct |
103 |
Correct |
123 ms |
29116 KB |
Output is correct |
104 |
Correct |
119 ms |
31672 KB |
Output is correct |