#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
char buf[1 << 23], * p1 = buf, * p2 = buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int rd()
{
int s = 0;
char ch = getchar(), lst;
while (ch < '0' || ch>'9') lst = ch, ch = getchar();
while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return lst == '-' ? -s : s;
}
int num[100];
inline void rt(int x)
{
if (x < 0) putchar('-'), x = -x;;
int len = 0;
do num[len++] = x % 10; while (x /= 10);
while (len--) putchar(num[len] + '0');
}
const int maxn = 2e5 + 500;
vector<vector<int>> adj(maxn),mrk(maxn);
vector<int> par, sz, s(maxn), inserted(maxn), power(maxn),vis(maxn), win(maxn,1), rep(maxn);
void init(int n) {
par.resize(n); sz.resize(n);
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
}
int find(int x) {
if (par[x] == x) return x;
else return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return;
if (sz[x] < sz[y]) swap(x, y);
par[y] = x;
sz[x] += sz[y];
power[x] += power[y];
}
bool same(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return true;
else return false;
}
//remember to init(n+5) and total_groups=n
void dfs(int u,int flag) {
win[u] &= flag;
for (auto& v : mrk[u]) dfs(v, win[u]);
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n = rd(), m = rd();
for (int i = 0; i < n; i++) {
s[i] = rd(); power[i] = s[i];
}
for (int i = 0; i < m; i++) {
int u = rd(), v = rd();
u--; v--;
adj[u].pb(v); adj[v].pb(u);
}
init(n + 5);
vector<pii> ord;
for (int i = 0; i < n; i++) ord.push_back(mp(s[i], i));
sort(ord.begin(), ord.end());
//note that rep[find(v)] is important:
//due to path compression: leader is the one with largest size not max
//need to reset leader to u
for (auto &t : ord) {
int u = t.second;
for (int v : adj[u]) if (inserted[v]) {
int w = rep[find(v)];
if (power[find(v)] < s[u]) {
win[w] = 0;
}
if (!vis[w]) {
mrk[u].push_back(w);
vis[w] = 1;
}
}
for (int v : adj[u]) if (inserted[v]) vis[rep[find(v)]] = 0;
for (int v : adj[u]) if (inserted[v]) unite(u, v);
rep[find(u)] = u;
inserted[u] = 1;
}
dfs(ord[n-1].second,1);
for (int i = 0; i < n; i++)rt(win[i]);
}
Compilation message
island.cpp: In function 'long long int rd()':
island.cpp:23:20: warning: 'lst' may be used uninitialized in this function [-Wmaybe-uninitialized]
23 | return lst == '-' ? -s : s;
| ~~~~~~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19112 KB |
Output is correct |
2 |
Correct |
9 ms |
19156 KB |
Output is correct |
3 |
Correct |
10 ms |
19144 KB |
Output is correct |
4 |
Correct |
10 ms |
19284 KB |
Output is correct |
5 |
Correct |
10 ms |
19284 KB |
Output is correct |
6 |
Correct |
10 ms |
19296 KB |
Output is correct |
7 |
Correct |
10 ms |
19284 KB |
Output is correct |
8 |
Correct |
10 ms |
19284 KB |
Output is correct |
9 |
Correct |
9 ms |
19384 KB |
Output is correct |
10 |
Correct |
12 ms |
19284 KB |
Output is correct |
11 |
Correct |
14 ms |
19384 KB |
Output is correct |
12 |
Correct |
12 ms |
19284 KB |
Output is correct |
13 |
Correct |
11 ms |
19412 KB |
Output is correct |
14 |
Correct |
10 ms |
19296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19156 KB |
Output is correct |
2 |
Correct |
9 ms |
19104 KB |
Output is correct |
3 |
Correct |
117 ms |
41688 KB |
Output is correct |
4 |
Correct |
119 ms |
46648 KB |
Output is correct |
5 |
Correct |
157 ms |
38520 KB |
Output is correct |
6 |
Correct |
163 ms |
39100 KB |
Output is correct |
7 |
Correct |
185 ms |
39144 KB |
Output is correct |
8 |
Correct |
125 ms |
47344 KB |
Output is correct |
9 |
Correct |
125 ms |
38612 KB |
Output is correct |
10 |
Correct |
111 ms |
39048 KB |
Output is correct |
11 |
Correct |
112 ms |
47960 KB |
Output is correct |
12 |
Correct |
182 ms |
41216 KB |
Output is correct |
13 |
Correct |
115 ms |
46472 KB |
Output is correct |
14 |
Correct |
111 ms |
45732 KB |
Output is correct |
15 |
Correct |
109 ms |
46420 KB |
Output is correct |
16 |
Correct |
68 ms |
46176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19156 KB |
Output is correct |
2 |
Correct |
215 ms |
37968 KB |
Output is correct |
3 |
Correct |
226 ms |
38064 KB |
Output is correct |
4 |
Correct |
140 ms |
46432 KB |
Output is correct |
5 |
Correct |
121 ms |
44388 KB |
Output is correct |
6 |
Correct |
203 ms |
38040 KB |
Output is correct |
7 |
Correct |
133 ms |
46388 KB |
Output is correct |
8 |
Correct |
130 ms |
46424 KB |
Output is correct |
9 |
Correct |
69 ms |
46140 KB |
Output is correct |
10 |
Correct |
123 ms |
40212 KB |
Output is correct |
11 |
Correct |
132 ms |
39260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19156 KB |
Output is correct |
2 |
Correct |
229 ms |
39324 KB |
Output is correct |
3 |
Correct |
220 ms |
39152 KB |
Output is correct |
4 |
Correct |
217 ms |
39100 KB |
Output is correct |
5 |
Correct |
192 ms |
39092 KB |
Output is correct |
6 |
Correct |
183 ms |
39288 KB |
Output is correct |
7 |
Correct |
104 ms |
43012 KB |
Output is correct |
8 |
Correct |
76 ms |
47932 KB |
Output is correct |
9 |
Correct |
101 ms |
32904 KB |
Output is correct |
10 |
Correct |
178 ms |
39108 KB |
Output is correct |
11 |
Correct |
139 ms |
39220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19112 KB |
Output is correct |
2 |
Correct |
9 ms |
19156 KB |
Output is correct |
3 |
Correct |
10 ms |
19144 KB |
Output is correct |
4 |
Correct |
10 ms |
19284 KB |
Output is correct |
5 |
Correct |
10 ms |
19284 KB |
Output is correct |
6 |
Correct |
10 ms |
19296 KB |
Output is correct |
7 |
Correct |
10 ms |
19284 KB |
Output is correct |
8 |
Correct |
10 ms |
19284 KB |
Output is correct |
9 |
Correct |
9 ms |
19384 KB |
Output is correct |
10 |
Correct |
12 ms |
19284 KB |
Output is correct |
11 |
Correct |
14 ms |
19384 KB |
Output is correct |
12 |
Correct |
12 ms |
19284 KB |
Output is correct |
13 |
Correct |
11 ms |
19412 KB |
Output is correct |
14 |
Correct |
10 ms |
19296 KB |
Output is correct |
15 |
Correct |
10 ms |
19156 KB |
Output is correct |
16 |
Correct |
9 ms |
19104 KB |
Output is correct |
17 |
Correct |
117 ms |
41688 KB |
Output is correct |
18 |
Correct |
119 ms |
46648 KB |
Output is correct |
19 |
Correct |
157 ms |
38520 KB |
Output is correct |
20 |
Correct |
163 ms |
39100 KB |
Output is correct |
21 |
Correct |
185 ms |
39144 KB |
Output is correct |
22 |
Correct |
125 ms |
47344 KB |
Output is correct |
23 |
Correct |
125 ms |
38612 KB |
Output is correct |
24 |
Correct |
111 ms |
39048 KB |
Output is correct |
25 |
Correct |
112 ms |
47960 KB |
Output is correct |
26 |
Correct |
182 ms |
41216 KB |
Output is correct |
27 |
Correct |
115 ms |
46472 KB |
Output is correct |
28 |
Correct |
111 ms |
45732 KB |
Output is correct |
29 |
Correct |
109 ms |
46420 KB |
Output is correct |
30 |
Correct |
68 ms |
46176 KB |
Output is correct |
31 |
Correct |
10 ms |
19156 KB |
Output is correct |
32 |
Correct |
215 ms |
37968 KB |
Output is correct |
33 |
Correct |
226 ms |
38064 KB |
Output is correct |
34 |
Correct |
140 ms |
46432 KB |
Output is correct |
35 |
Correct |
121 ms |
44388 KB |
Output is correct |
36 |
Correct |
203 ms |
38040 KB |
Output is correct |
37 |
Correct |
133 ms |
46388 KB |
Output is correct |
38 |
Correct |
130 ms |
46424 KB |
Output is correct |
39 |
Correct |
69 ms |
46140 KB |
Output is correct |
40 |
Correct |
123 ms |
40212 KB |
Output is correct |
41 |
Correct |
132 ms |
39260 KB |
Output is correct |
42 |
Correct |
9 ms |
19156 KB |
Output is correct |
43 |
Correct |
229 ms |
39324 KB |
Output is correct |
44 |
Correct |
220 ms |
39152 KB |
Output is correct |
45 |
Correct |
217 ms |
39100 KB |
Output is correct |
46 |
Correct |
192 ms |
39092 KB |
Output is correct |
47 |
Correct |
183 ms |
39288 KB |
Output is correct |
48 |
Correct |
104 ms |
43012 KB |
Output is correct |
49 |
Correct |
76 ms |
47932 KB |
Output is correct |
50 |
Correct |
101 ms |
32904 KB |
Output is correct |
51 |
Correct |
178 ms |
39108 KB |
Output is correct |
52 |
Correct |
139 ms |
39220 KB |
Output is correct |
53 |
Correct |
10 ms |
19156 KB |
Output is correct |
54 |
Correct |
9 ms |
19156 KB |
Output is correct |
55 |
Correct |
9 ms |
19144 KB |
Output is correct |
56 |
Correct |
11 ms |
19300 KB |
Output is correct |
57 |
Correct |
11 ms |
19284 KB |
Output is correct |
58 |
Correct |
10 ms |
19296 KB |
Output is correct |
59 |
Correct |
10 ms |
19284 KB |
Output is correct |
60 |
Correct |
10 ms |
19284 KB |
Output is correct |
61 |
Correct |
10 ms |
19412 KB |
Output is correct |
62 |
Correct |
12 ms |
19320 KB |
Output is correct |
63 |
Correct |
10 ms |
19284 KB |
Output is correct |
64 |
Correct |
10 ms |
19380 KB |
Output is correct |
65 |
Correct |
11 ms |
19412 KB |
Output is correct |
66 |
Correct |
10 ms |
19284 KB |
Output is correct |
67 |
Correct |
127 ms |
41640 KB |
Output is correct |
68 |
Correct |
128 ms |
46684 KB |
Output is correct |
69 |
Correct |
168 ms |
38452 KB |
Output is correct |
70 |
Correct |
176 ms |
39076 KB |
Output is correct |
71 |
Correct |
168 ms |
39072 KB |
Output is correct |
72 |
Correct |
131 ms |
47352 KB |
Output is correct |
73 |
Correct |
123 ms |
38692 KB |
Output is correct |
74 |
Correct |
118 ms |
39048 KB |
Output is correct |
75 |
Correct |
112 ms |
47980 KB |
Output is correct |
76 |
Correct |
196 ms |
41176 KB |
Output is correct |
77 |
Correct |
125 ms |
46388 KB |
Output is correct |
78 |
Correct |
109 ms |
45740 KB |
Output is correct |
79 |
Correct |
116 ms |
46488 KB |
Output is correct |
80 |
Correct |
68 ms |
46192 KB |
Output is correct |
81 |
Correct |
198 ms |
37960 KB |
Output is correct |
82 |
Correct |
199 ms |
38004 KB |
Output is correct |
83 |
Correct |
142 ms |
46384 KB |
Output is correct |
84 |
Correct |
108 ms |
44424 KB |
Output is correct |
85 |
Correct |
190 ms |
38096 KB |
Output is correct |
86 |
Correct |
138 ms |
46368 KB |
Output is correct |
87 |
Correct |
130 ms |
46384 KB |
Output is correct |
88 |
Correct |
114 ms |
40196 KB |
Output is correct |
89 |
Correct |
138 ms |
39348 KB |
Output is correct |
90 |
Correct |
249 ms |
39352 KB |
Output is correct |
91 |
Correct |
227 ms |
39040 KB |
Output is correct |
92 |
Correct |
238 ms |
39132 KB |
Output is correct |
93 |
Correct |
200 ms |
39120 KB |
Output is correct |
94 |
Correct |
176 ms |
39076 KB |
Output is correct |
95 |
Correct |
104 ms |
43060 KB |
Output is correct |
96 |
Correct |
79 ms |
47960 KB |
Output is correct |
97 |
Correct |
103 ms |
32856 KB |
Output is correct |
98 |
Correct |
173 ms |
39096 KB |
Output is correct |
99 |
Correct |
131 ms |
39252 KB |
Output is correct |
100 |
Correct |
32 ms |
25804 KB |
Output is correct |
101 |
Correct |
242 ms |
39068 KB |
Output is correct |
102 |
Correct |
146 ms |
37888 KB |
Output is correct |
103 |
Correct |
196 ms |
38480 KB |
Output is correct |
104 |
Correct |
244 ms |
39576 KB |
Output is correct |