Submission #999649

# Submission time Handle Problem Language Result Execution time Memory
999649 2024-06-16T02:20:04 Z pcc Stranded Far From Home (BOI22_island) C++17
100 / 100
264 ms 56264 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int mxn = 2e5+10;
bitset<mxn> done;
vector<int> paths[mxn];
vector<int> tree[mxn];
int N,M;
int arr[mxn];
bitset<mxn> ans;

struct DSU{
	int dsu[mxn];
	ll sum[mxn];
	priority_queue<pii,vector<pii>,greater<pii>> pq[mxn];
	void init(int n){
		for(int i = 0;i<n;i++)dsu[i] = i;
	}
	int root(int k){
		return k == dsu[k]?k:dsu[k] = root(dsu[k]);
	}
	void onion(int a,int b){
		a = root(a),b = root(b);
		if(a == b)return;
		if(pq[a].size()<pq[b].size())swap(a,b);
		while(!pq[b].empty()){
			pq[a].push(pq[b].top());
			pq[b].pop();
		}
		sum[a] += sum[b];
		dsu[b] = a;
		return;
	}
};
DSU dsu;

void dfs(int now){
	ans[now] = 1;
	for(auto nxt:tree[now]){
		if(!ans[nxt]){
			dfs(nxt);
		}
	}
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M;
	vector<int> perm;
	for(int i = 1;i<=N;i++)cin>>arr[i],dsu.sum[i] = arr[i],perm.push_back(i);
	sort(perm.begin(),perm.end(),[](int a,int b){return arr[a]<arr[b];});
	dsu.init(mxn);
	for(int i = 1;i<=M;i++){
		int a,b;
		cin>>a>>b;
		paths[a].push_back(b);
		paths[b].push_back(a);
		dsu.pq[a].push(pii(arr[b],b));
		dsu.pq[b].push(pii(arr[a],a));
	}
	for(auto now:perm){
		done[now] = true;
		for(auto nxt:paths[now]){
			if(done[nxt])dsu.onion(now,nxt);
		}
		int rt = dsu.root(now);
		while(!dsu.pq[rt].empty()&&done[dsu.pq[rt].top().sc])dsu.pq[rt].pop();
		if(!dsu.pq[rt].empty()&&dsu.pq[rt].top().fs<=dsu.sum[rt])tree[dsu.pq[rt].top().sc].push_back(now);
	}
	dfs(perm.back());
	for(int i = 1;i<=N;i++)cout<<ans[i];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19036 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
3 Correct 3 ms 19096 KB Output is correct
4 Correct 4 ms 19292 KB Output is correct
5 Correct 4 ms 19292 KB Output is correct
6 Correct 4 ms 19292 KB Output is correct
7 Correct 5 ms 19508 KB Output is correct
8 Correct 4 ms 19292 KB Output is correct
9 Correct 4 ms 19288 KB Output is correct
10 Correct 4 ms 19420 KB Output is correct
11 Correct 4 ms 19292 KB Output is correct
12 Correct 4 ms 19292 KB Output is correct
13 Correct 4 ms 19424 KB Output is correct
14 Correct 4 ms 19292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
3 Correct 134 ms 48292 KB Output is correct
4 Correct 199 ms 51312 KB Output is correct
5 Correct 141 ms 42892 KB Output is correct
6 Correct 161 ms 44020 KB Output is correct
7 Correct 130 ms 43800 KB Output is correct
8 Correct 208 ms 48296 KB Output is correct
9 Correct 122 ms 44644 KB Output is correct
10 Correct 137 ms 42440 KB Output is correct
11 Correct 129 ms 43412 KB Output is correct
12 Correct 170 ms 45004 KB Output is correct
13 Correct 186 ms 54020 KB Output is correct
14 Correct 229 ms 50636 KB Output is correct
15 Correct 128 ms 55800 KB Output is correct
16 Correct 91 ms 54736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19100 KB Output is correct
2 Correct 197 ms 45216 KB Output is correct
3 Correct 204 ms 45260 KB Output is correct
4 Correct 213 ms 55280 KB Output is correct
5 Correct 201 ms 50888 KB Output is correct
6 Correct 219 ms 45568 KB Output is correct
7 Correct 177 ms 56008 KB Output is correct
8 Correct 151 ms 56008 KB Output is correct
9 Correct 98 ms 54736 KB Output is correct
10 Correct 208 ms 45996 KB Output is correct
11 Correct 169 ms 45004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19036 KB Output is correct
2 Correct 182 ms 43484 KB Output is correct
3 Correct 206 ms 43468 KB Output is correct
4 Correct 174 ms 43920 KB Output is correct
5 Correct 225 ms 55500 KB Output is correct
6 Correct 233 ms 50428 KB Output is correct
7 Correct 134 ms 45000 KB Output is correct
8 Correct 158 ms 50888 KB Output is correct
9 Correct 136 ms 35052 KB Output is correct
10 Correct 215 ms 52168 KB Output is correct
11 Correct 164 ms 45260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19036 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
3 Correct 3 ms 19096 KB Output is correct
4 Correct 4 ms 19292 KB Output is correct
5 Correct 4 ms 19292 KB Output is correct
6 Correct 4 ms 19292 KB Output is correct
7 Correct 5 ms 19508 KB Output is correct
8 Correct 4 ms 19292 KB Output is correct
9 Correct 4 ms 19288 KB Output is correct
10 Correct 4 ms 19420 KB Output is correct
11 Correct 4 ms 19292 KB Output is correct
12 Correct 4 ms 19292 KB Output is correct
13 Correct 4 ms 19424 KB Output is correct
14 Correct 4 ms 19292 KB Output is correct
15 Correct 4 ms 19036 KB Output is correct
16 Correct 3 ms 19036 KB Output is correct
17 Correct 134 ms 48292 KB Output is correct
18 Correct 199 ms 51312 KB Output is correct
19 Correct 141 ms 42892 KB Output is correct
20 Correct 161 ms 44020 KB Output is correct
21 Correct 130 ms 43800 KB Output is correct
22 Correct 208 ms 48296 KB Output is correct
23 Correct 122 ms 44644 KB Output is correct
24 Correct 137 ms 42440 KB Output is correct
25 Correct 129 ms 43412 KB Output is correct
26 Correct 170 ms 45004 KB Output is correct
27 Correct 186 ms 54020 KB Output is correct
28 Correct 229 ms 50636 KB Output is correct
29 Correct 128 ms 55800 KB Output is correct
30 Correct 91 ms 54736 KB Output is correct
31 Correct 3 ms 19100 KB Output is correct
32 Correct 197 ms 45216 KB Output is correct
33 Correct 204 ms 45260 KB Output is correct
34 Correct 213 ms 55280 KB Output is correct
35 Correct 201 ms 50888 KB Output is correct
36 Correct 219 ms 45568 KB Output is correct
37 Correct 177 ms 56008 KB Output is correct
38 Correct 151 ms 56008 KB Output is correct
39 Correct 98 ms 54736 KB Output is correct
40 Correct 208 ms 45996 KB Output is correct
41 Correct 169 ms 45004 KB Output is correct
42 Correct 3 ms 19036 KB Output is correct
43 Correct 182 ms 43484 KB Output is correct
44 Correct 206 ms 43468 KB Output is correct
45 Correct 174 ms 43920 KB Output is correct
46 Correct 225 ms 55500 KB Output is correct
47 Correct 233 ms 50428 KB Output is correct
48 Correct 134 ms 45000 KB Output is correct
49 Correct 158 ms 50888 KB Output is correct
50 Correct 136 ms 35052 KB Output is correct
51 Correct 215 ms 52168 KB Output is correct
52 Correct 164 ms 45260 KB Output is correct
53 Correct 3 ms 19036 KB Output is correct
54 Correct 3 ms 19036 KB Output is correct
55 Correct 3 ms 19036 KB Output is correct
56 Correct 4 ms 19288 KB Output is correct
57 Correct 5 ms 19292 KB Output is correct
58 Correct 4 ms 19520 KB Output is correct
59 Correct 4 ms 19292 KB Output is correct
60 Correct 4 ms 19292 KB Output is correct
61 Correct 4 ms 19292 KB Output is correct
62 Correct 4 ms 19292 KB Output is correct
63 Correct 5 ms 19532 KB Output is correct
64 Correct 4 ms 19292 KB Output is correct
65 Correct 5 ms 19548 KB Output is correct
66 Correct 4 ms 19292 KB Output is correct
67 Correct 152 ms 48332 KB Output is correct
68 Correct 203 ms 51512 KB Output is correct
69 Correct 173 ms 42956 KB Output is correct
70 Correct 145 ms 43724 KB Output is correct
71 Correct 168 ms 43776 KB Output is correct
72 Correct 230 ms 48132 KB Output is correct
73 Correct 122 ms 44492 KB Output is correct
74 Correct 172 ms 41672 KB Output is correct
75 Correct 132 ms 43972 KB Output is correct
76 Correct 171 ms 44824 KB Output is correct
77 Correct 189 ms 53448 KB Output is correct
78 Correct 171 ms 50632 KB Output is correct
79 Correct 148 ms 55788 KB Output is correct
80 Correct 91 ms 54732 KB Output is correct
81 Correct 190 ms 45008 KB Output is correct
82 Correct 187 ms 45264 KB Output is correct
83 Correct 207 ms 56264 KB Output is correct
84 Correct 178 ms 50888 KB Output is correct
85 Correct 164 ms 45264 KB Output is correct
86 Correct 175 ms 55864 KB Output is correct
87 Correct 157 ms 56008 KB Output is correct
88 Correct 170 ms 46028 KB Output is correct
89 Correct 175 ms 45000 KB Output is correct
90 Correct 194 ms 43464 KB Output is correct
91 Correct 180 ms 43472 KB Output is correct
92 Correct 176 ms 43984 KB Output is correct
93 Correct 264 ms 54216 KB Output is correct
94 Correct 206 ms 51148 KB Output is correct
95 Correct 137 ms 45256 KB Output is correct
96 Correct 160 ms 50640 KB Output is correct
97 Correct 126 ms 34768 KB Output is correct
98 Correct 241 ms 52176 KB Output is correct
99 Correct 180 ms 45260 KB Output is correct
100 Correct 101 ms 28940 KB Output is correct
101 Correct 202 ms 43240 KB Output is correct
102 Correct 181 ms 44996 KB Output is correct
103 Correct 228 ms 42704 KB Output is correct
104 Correct 183 ms 44064 KB Output is correct