#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;
struct DSU {
int n;
vector<ll> fa;
vector<ll> cnt;
vector<ll> del;
DSU(int _n,vector<pll> &w):n(_n) {
fa.resize(n+1);
cnt.resize(n+1);
del.resize(n+1);
for (int i=0;i<n;i++) {
cnt[w[i].S]=w[i].F;
}
iota(all(fa),0);
}
pll get(ll x) {
if (fa[x]==x) return {del[x],x};
else {
pll ret = get(fa[x]);
del[x]|=ret.F;
fa[x]=ret.S;
return {del[x]|ret.F,ret.S};
}
}
void unionn(int a,int b) {
a=get(a).S;b=get(b).S;
if (a==b) return;
fa[a]=b;
cnt[b]+=cnt[a];
}
};
int main() {
speed;
int n,m;
cin>>n>>m;
vvector<ll> G(n+1);
vector<pll> w;
vector<ll> cnt(n+1);
for (int i=1;i<=n;i++) {
cin>>cnt[i];
w.emplace_back(cnt[i],i);
}
sort(all(w));
for (int i=0;i<m;i++) {
ll a,b;
cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
}
DSU d(n,w);
for (int i=1;i<n;i++) {
ll v=w[i].S;
for (ll u:G[v]) {
if (cnt[u]>cnt[v]) continue;
ll ru=d.get(u).S;
if (d.cnt[ru]<cnt[v]) d.del[ru]=true;
d.unionn(u,v);
}
}
for (int i=1;i<=n;i++) {
pll ret = d.get(i);
cout<<!(d.del[i]);
}
return 0;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:86:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
86 | pll ret = d.get(i);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
396 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
101 ms |
22968 KB |
Output is correct |
4 |
Correct |
114 ms |
22984 KB |
Output is correct |
5 |
Correct |
102 ms |
26552 KB |
Output is correct |
6 |
Correct |
114 ms |
27168 KB |
Output is correct |
7 |
Correct |
110 ms |
27316 KB |
Output is correct |
8 |
Correct |
105 ms |
27320 KB |
Output is correct |
9 |
Correct |
103 ms |
28592 KB |
Output is correct |
10 |
Correct |
75 ms |
27024 KB |
Output is correct |
11 |
Correct |
94 ms |
26844 KB |
Output is correct |
12 |
Correct |
120 ms |
25784 KB |
Output is correct |
13 |
Correct |
94 ms |
24828 KB |
Output is correct |
14 |
Correct |
92 ms |
24928 KB |
Output is correct |
15 |
Correct |
129 ms |
26368 KB |
Output is correct |
16 |
Correct |
59 ms |
25532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
135 ms |
21660 KB |
Output is correct |
3 |
Correct |
142 ms |
26176 KB |
Output is correct |
4 |
Correct |
162 ms |
26304 KB |
Output is correct |
5 |
Correct |
123 ms |
24688 KB |
Output is correct |
6 |
Correct |
109 ms |
26296 KB |
Output is correct |
7 |
Correct |
131 ms |
26316 KB |
Output is correct |
8 |
Correct |
110 ms |
26220 KB |
Output is correct |
9 |
Correct |
66 ms |
25528 KB |
Output is correct |
10 |
Correct |
96 ms |
26892 KB |
Output is correct |
11 |
Correct |
110 ms |
25204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
128 ms |
22712 KB |
Output is correct |
3 |
Correct |
148 ms |
27060 KB |
Output is correct |
4 |
Correct |
149 ms |
27244 KB |
Output is correct |
5 |
Correct |
136 ms |
27320 KB |
Output is correct |
6 |
Correct |
112 ms |
26552 KB |
Output is correct |
7 |
Correct |
86 ms |
28204 KB |
Output is correct |
8 |
Correct |
71 ms |
27832 KB |
Output is correct |
9 |
Correct |
82 ms |
16208 KB |
Output is correct |
10 |
Correct |
110 ms |
25784 KB |
Output is correct |
11 |
Correct |
102 ms |
25072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
396 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
101 ms |
22968 KB |
Output is correct |
18 |
Correct |
114 ms |
22984 KB |
Output is correct |
19 |
Correct |
102 ms |
26552 KB |
Output is correct |
20 |
Correct |
114 ms |
27168 KB |
Output is correct |
21 |
Correct |
110 ms |
27316 KB |
Output is correct |
22 |
Correct |
105 ms |
27320 KB |
Output is correct |
23 |
Correct |
103 ms |
28592 KB |
Output is correct |
24 |
Correct |
75 ms |
27024 KB |
Output is correct |
25 |
Correct |
94 ms |
26844 KB |
Output is correct |
26 |
Correct |
120 ms |
25784 KB |
Output is correct |
27 |
Correct |
94 ms |
24828 KB |
Output is correct |
28 |
Correct |
92 ms |
24928 KB |
Output is correct |
29 |
Correct |
129 ms |
26368 KB |
Output is correct |
30 |
Correct |
59 ms |
25532 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
135 ms |
21660 KB |
Output is correct |
33 |
Correct |
142 ms |
26176 KB |
Output is correct |
34 |
Correct |
162 ms |
26304 KB |
Output is correct |
35 |
Correct |
123 ms |
24688 KB |
Output is correct |
36 |
Correct |
109 ms |
26296 KB |
Output is correct |
37 |
Correct |
131 ms |
26316 KB |
Output is correct |
38 |
Correct |
110 ms |
26220 KB |
Output is correct |
39 |
Correct |
66 ms |
25528 KB |
Output is correct |
40 |
Correct |
96 ms |
26892 KB |
Output is correct |
41 |
Correct |
110 ms |
25204 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
128 ms |
22712 KB |
Output is correct |
44 |
Correct |
148 ms |
27060 KB |
Output is correct |
45 |
Correct |
149 ms |
27244 KB |
Output is correct |
46 |
Correct |
136 ms |
27320 KB |
Output is correct |
47 |
Correct |
112 ms |
26552 KB |
Output is correct |
48 |
Correct |
86 ms |
28204 KB |
Output is correct |
49 |
Correct |
71 ms |
27832 KB |
Output is correct |
50 |
Correct |
82 ms |
16208 KB |
Output is correct |
51 |
Correct |
110 ms |
25784 KB |
Output is correct |
52 |
Correct |
102 ms |
25072 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
2 ms |
592 KB |
Output is correct |
57 |
Correct |
2 ms |
592 KB |
Output is correct |
58 |
Correct |
1 ms |
592 KB |
Output is correct |
59 |
Correct |
1 ms |
592 KB |
Output is correct |
60 |
Correct |
2 ms |
592 KB |
Output is correct |
61 |
Correct |
2 ms |
760 KB |
Output is correct |
62 |
Correct |
2 ms |
472 KB |
Output is correct |
63 |
Correct |
2 ms |
592 KB |
Output is correct |
64 |
Correct |
2 ms |
620 KB |
Output is correct |
65 |
Correct |
1 ms |
472 KB |
Output is correct |
66 |
Correct |
2 ms |
592 KB |
Output is correct |
67 |
Correct |
98 ms |
27312 KB |
Output is correct |
68 |
Correct |
82 ms |
26040 KB |
Output is correct |
69 |
Correct |
105 ms |
26552 KB |
Output is correct |
70 |
Correct |
113 ms |
27320 KB |
Output is correct |
71 |
Correct |
94 ms |
27320 KB |
Output is correct |
72 |
Correct |
85 ms |
27328 KB |
Output is correct |
73 |
Correct |
82 ms |
28600 KB |
Output is correct |
74 |
Correct |
66 ms |
27064 KB |
Output is correct |
75 |
Correct |
98 ms |
26820 KB |
Output is correct |
76 |
Correct |
79 ms |
25784 KB |
Output is correct |
77 |
Correct |
78 ms |
24760 KB |
Output is correct |
78 |
Correct |
75 ms |
25016 KB |
Output is correct |
79 |
Correct |
80 ms |
26244 KB |
Output is correct |
80 |
Correct |
59 ms |
25280 KB |
Output is correct |
81 |
Correct |
99 ms |
26296 KB |
Output is correct |
82 |
Correct |
105 ms |
26300 KB |
Output is correct |
83 |
Correct |
97 ms |
26360 KB |
Output is correct |
84 |
Correct |
77 ms |
24760 KB |
Output is correct |
85 |
Correct |
98 ms |
26296 KB |
Output is correct |
86 |
Correct |
96 ms |
26424 KB |
Output is correct |
87 |
Correct |
96 ms |
26420 KB |
Output is correct |
88 |
Correct |
78 ms |
26808 KB |
Output is correct |
89 |
Correct |
94 ms |
25272 KB |
Output is correct |
90 |
Correct |
122 ms |
27288 KB |
Output is correct |
91 |
Correct |
130 ms |
27064 KB |
Output is correct |
92 |
Correct |
119 ms |
27320 KB |
Output is correct |
93 |
Correct |
126 ms |
27328 KB |
Output is correct |
94 |
Correct |
114 ms |
26552 KB |
Output is correct |
95 |
Correct |
93 ms |
28212 KB |
Output is correct |
96 |
Correct |
69 ms |
27828 KB |
Output is correct |
97 |
Correct |
77 ms |
16328 KB |
Output is correct |
98 |
Correct |
132 ms |
25916 KB |
Output is correct |
99 |
Correct |
94 ms |
25272 KB |
Output is correct |
100 |
Correct |
34 ms |
6992 KB |
Output is correct |
101 |
Correct |
147 ms |
27452 KB |
Output is correct |
102 |
Correct |
117 ms |
23884 KB |
Output is correct |
103 |
Correct |
125 ms |
24760 KB |
Output is correct |
104 |
Correct |
141 ms |
27076 KB |
Output is correct |