Submission #604825

# Submission time Handle Problem Language Result Execution time Memory
604825 2022-07-25T10:10:05 Z errorgorn Stranded Far From Home (BOI22_island) C++17
100 / 100
510 ms 71232 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct UFDS{
	int p[200005];
	
	UFDS(){
		rep(x,0,200005) p[x]=x;
	}
	
	int par(int i){
		if (p[i]==i) return i;
		else return p[i]=par(p[i]);
	}
} ufds;

int n,m;
int arr[200005];
vector<iii> edges;
set<int> s[200005];

signed main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n>>m;
	rep(x,1,n+1) cin>>arr[x];
	
	int a,b;
	rep(x,0,m){
		cin>>a>>b;
		if (arr[a]<arr[b]) swap(a,b);
		edges.pub({arr[a],a,b});
	}
	
	sort(all(edges));
	rep(x,1,n+1) s[x].insert(x);
	
	for (auto [w,a,b]:edges){
		a=ufds.par(a),b=ufds.par(b);
		if (a==b) continue;
		
		if (arr[b]>=w){
			if (sz(s[a])<sz(s[b])) swap(s[a],s[b]);
			for (auto it:s[b]) s[a].insert(it);
		}
		arr[a]+=arr[b];
		ufds.p[b]=a;
	}
	
	int idx=ufds.par(1);
	
	string ans(n,'0');
	for (auto it:s[idx]) ans[it-1]='1';
	
	cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11220 KB Output is correct
2 Correct 6 ms 11296 KB Output is correct
3 Correct 5 ms 11300 KB Output is correct
4 Correct 7 ms 11476 KB Output is correct
5 Correct 7 ms 11476 KB Output is correct
6 Correct 7 ms 11476 KB Output is correct
7 Correct 7 ms 11436 KB Output is correct
8 Correct 6 ms 11440 KB Output is correct
9 Correct 7 ms 11476 KB Output is correct
10 Correct 7 ms 11584 KB Output is correct
11 Correct 7 ms 11604 KB Output is correct
12 Correct 7 ms 11604 KB Output is correct
13 Correct 9 ms 11476 KB Output is correct
14 Correct 7 ms 11560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11220 KB Output is correct
2 Correct 6 ms 11220 KB Output is correct
3 Correct 135 ms 38256 KB Output is correct
4 Correct 120 ms 39076 KB Output is correct
5 Correct 232 ms 47800 KB Output is correct
6 Correct 202 ms 50732 KB Output is correct
7 Correct 200 ms 50748 KB Output is correct
8 Correct 244 ms 39264 KB Output is correct
9 Correct 179 ms 60212 KB Output is correct
10 Correct 96 ms 30340 KB Output is correct
11 Correct 142 ms 39580 KB Output is correct
12 Correct 211 ms 37780 KB Output is correct
13 Correct 131 ms 39208 KB Output is correct
14 Correct 152 ms 40288 KB Output is correct
15 Correct 140 ms 40280 KB Output is correct
16 Correct 129 ms 39136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11220 KB Output is correct
2 Correct 264 ms 59196 KB Output is correct
3 Correct 251 ms 58308 KB Output is correct
4 Correct 170 ms 42132 KB Output is correct
5 Correct 128 ms 40292 KB Output is correct
6 Correct 238 ms 58524 KB Output is correct
7 Correct 187 ms 40044 KB Output is correct
8 Correct 144 ms 39984 KB Output is correct
9 Correct 113 ms 38896 KB Output is correct
10 Correct 120 ms 34964 KB Output is correct
11 Correct 150 ms 41484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11300 KB Output is correct
2 Correct 251 ms 44900 KB Output is correct
3 Correct 280 ms 49080 KB Output is correct
4 Correct 310 ms 53692 KB Output is correct
5 Correct 481 ms 66984 KB Output is correct
6 Correct 351 ms 53484 KB Output is correct
7 Correct 139 ms 41376 KB Output is correct
8 Correct 138 ms 40532 KB Output is correct
9 Correct 128 ms 29940 KB Output is correct
10 Correct 510 ms 70488 KB Output is correct
11 Correct 185 ms 40508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11220 KB Output is correct
2 Correct 6 ms 11296 KB Output is correct
3 Correct 5 ms 11300 KB Output is correct
4 Correct 7 ms 11476 KB Output is correct
5 Correct 7 ms 11476 KB Output is correct
6 Correct 7 ms 11476 KB Output is correct
7 Correct 7 ms 11436 KB Output is correct
8 Correct 6 ms 11440 KB Output is correct
9 Correct 7 ms 11476 KB Output is correct
10 Correct 7 ms 11584 KB Output is correct
11 Correct 7 ms 11604 KB Output is correct
12 Correct 7 ms 11604 KB Output is correct
13 Correct 9 ms 11476 KB Output is correct
14 Correct 7 ms 11560 KB Output is correct
15 Correct 6 ms 11220 KB Output is correct
16 Correct 6 ms 11220 KB Output is correct
17 Correct 135 ms 38256 KB Output is correct
18 Correct 120 ms 39076 KB Output is correct
19 Correct 232 ms 47800 KB Output is correct
20 Correct 202 ms 50732 KB Output is correct
21 Correct 200 ms 50748 KB Output is correct
22 Correct 244 ms 39264 KB Output is correct
23 Correct 179 ms 60212 KB Output is correct
24 Correct 96 ms 30340 KB Output is correct
25 Correct 142 ms 39580 KB Output is correct
26 Correct 211 ms 37780 KB Output is correct
27 Correct 131 ms 39208 KB Output is correct
28 Correct 152 ms 40288 KB Output is correct
29 Correct 140 ms 40280 KB Output is correct
30 Correct 129 ms 39136 KB Output is correct
31 Correct 7 ms 11220 KB Output is correct
32 Correct 264 ms 59196 KB Output is correct
33 Correct 251 ms 58308 KB Output is correct
34 Correct 170 ms 42132 KB Output is correct
35 Correct 128 ms 40292 KB Output is correct
36 Correct 238 ms 58524 KB Output is correct
37 Correct 187 ms 40044 KB Output is correct
38 Correct 144 ms 39984 KB Output is correct
39 Correct 113 ms 38896 KB Output is correct
40 Correct 120 ms 34964 KB Output is correct
41 Correct 150 ms 41484 KB Output is correct
42 Correct 6 ms 11300 KB Output is correct
43 Correct 251 ms 44900 KB Output is correct
44 Correct 280 ms 49080 KB Output is correct
45 Correct 310 ms 53692 KB Output is correct
46 Correct 481 ms 66984 KB Output is correct
47 Correct 351 ms 53484 KB Output is correct
48 Correct 139 ms 41376 KB Output is correct
49 Correct 138 ms 40532 KB Output is correct
50 Correct 128 ms 29940 KB Output is correct
51 Correct 510 ms 70488 KB Output is correct
52 Correct 185 ms 40508 KB Output is correct
53 Correct 7 ms 11216 KB Output is correct
54 Correct 6 ms 11220 KB Output is correct
55 Correct 6 ms 11220 KB Output is correct
56 Correct 8 ms 11444 KB Output is correct
57 Correct 11 ms 11604 KB Output is correct
58 Correct 7 ms 11476 KB Output is correct
59 Correct 7 ms 11476 KB Output is correct
60 Correct 9 ms 11476 KB Output is correct
61 Correct 7 ms 11564 KB Output is correct
62 Correct 9 ms 11564 KB Output is correct
63 Correct 7 ms 11592 KB Output is correct
64 Correct 10 ms 11572 KB Output is correct
65 Correct 10 ms 11516 KB Output is correct
66 Correct 10 ms 11604 KB Output is correct
67 Correct 162 ms 40312 KB Output is correct
68 Correct 123 ms 40404 KB Output is correct
69 Correct 223 ms 50488 KB Output is correct
70 Correct 255 ms 52188 KB Output is correct
71 Correct 236 ms 49548 KB Output is correct
72 Correct 240 ms 39740 KB Output is correct
73 Correct 193 ms 60780 KB Output is correct
74 Correct 109 ms 29060 KB Output is correct
75 Correct 175 ms 38804 KB Output is correct
76 Correct 197 ms 37780 KB Output is correct
77 Correct 149 ms 39820 KB Output is correct
78 Correct 152 ms 39600 KB Output is correct
79 Correct 153 ms 40348 KB Output is correct
80 Correct 125 ms 40108 KB Output is correct
81 Correct 267 ms 58692 KB Output is correct
82 Correct 301 ms 58748 KB Output is correct
83 Correct 150 ms 38112 KB Output is correct
84 Correct 154 ms 39872 KB Output is correct
85 Correct 282 ms 59696 KB Output is correct
86 Correct 160 ms 41104 KB Output is correct
87 Correct 172 ms 40924 KB Output is correct
88 Correct 132 ms 34296 KB Output is correct
89 Correct 161 ms 38884 KB Output is correct
90 Correct 273 ms 44204 KB Output is correct
91 Correct 293 ms 49308 KB Output is correct
92 Correct 343 ms 56484 KB Output is correct
93 Correct 440 ms 66168 KB Output is correct
94 Correct 409 ms 52988 KB Output is correct
95 Correct 153 ms 40640 KB Output is correct
96 Correct 186 ms 40204 KB Output is correct
97 Correct 141 ms 29580 KB Output is correct
98 Correct 463 ms 71232 KB Output is correct
99 Correct 173 ms 41204 KB Output is correct
100 Correct 82 ms 18924 KB Output is correct
101 Correct 321 ms 50300 KB Output is correct
102 Correct 342 ms 42308 KB Output is correct
103 Correct 238 ms 32812 KB Output is correct
104 Correct 301 ms 38960 KB Output is correct