답안 #648238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648238 2022-10-05T19:29:35 Z beaconmc Stranded Far From Home (BOI22_island) C++17
100 / 100
378 ms 42756 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;


#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)


ll cc[200001];
ll siz[200001];
ll sizes[200001];
vector<ll> stuff[200001];
ll ans[200001];
vector<vector<ll>> edges;

ll n,m;
int find(ll a){
	while (cc[a] != a){
		cc[a] = cc[cc[a]];
		a = cc[a];
	}
	return a;
}

void unite(ll a,ll b){
	ll aa = find(a);
	ll bb = find(b);
	if (aa==bb) return;

	if (siz[aa] < sizes[b]){
		for (auto&i : stuff[aa]){
			ans[i] = 0;
		}
		stuff[aa] = {};
	}
	if (siz[bb] < sizes[a]){
		for (auto&i : stuff[bb]){
			ans[i] = 0;
		}
		stuff[bb] = {};
	}

	if (stuff[aa].size() > stuff[bb].size()){
		swap(stuff[aa], stuff[bb]);
	}
	for (auto&i : stuff[aa]){
		stuff[bb].push_back(i);
	}

	siz[bb] += siz[aa];
	cc[aa] = bb;
}

int main(){
	cin >> n >> m;
	FOR(i,0,n){
		cc[i] = i;
		cin >> sizes[i];
		siz[i] = sizes[i];
		stuff[i].push_back(i);
		ans[i] = 1;
	}

	FOR(i,0,m){
		ll a,b;
		cin >> a >> b;
		a--;b--;
		edges.push_back({max(sizes[a],sizes[b]), a,b});
	}

	sort(edges.begin(), edges.end());

	for (auto&i : edges){
		unite(i[1],i[2]);
	}
	FOR(i,0,n) cout << ans[i];


}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 5 ms 5228 KB Output is correct
5 Correct 5 ms 5204 KB Output is correct
6 Correct 5 ms 5204 KB Output is correct
7 Correct 5 ms 5204 KB Output is correct
8 Correct 5 ms 5240 KB Output is correct
9 Correct 4 ms 5204 KB Output is correct
10 Correct 5 ms 5332 KB Output is correct
11 Correct 4 ms 5204 KB Output is correct
12 Correct 5 ms 5332 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 286 ms 31932 KB Output is correct
4 Correct 252 ms 35172 KB Output is correct
5 Correct 305 ms 38492 KB Output is correct
6 Correct 335 ms 39716 KB Output is correct
7 Correct 325 ms 39756 KB Output is correct
8 Correct 312 ms 36664 KB Output is correct
9 Correct 309 ms 42572 KB Output is correct
10 Correct 285 ms 32368 KB Output is correct
11 Correct 259 ms 35664 KB Output is correct
12 Correct 288 ms 34016 KB Output is correct
13 Correct 240 ms 35108 KB Output is correct
14 Correct 255 ms 35132 KB Output is correct
15 Correct 283 ms 36720 KB Output is correct
16 Correct 210 ms 35692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 342 ms 36648 KB Output is correct
3 Correct 351 ms 41464 KB Output is correct
4 Correct 318 ms 36704 KB Output is correct
5 Correct 253 ms 34696 KB Output is correct
6 Correct 336 ms 41184 KB Output is correct
7 Correct 284 ms 36720 KB Output is correct
8 Correct 276 ms 36664 KB Output is correct
9 Correct 210 ms 35656 KB Output is correct
10 Correct 260 ms 34164 KB Output is correct
11 Correct 256 ms 34840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 341 ms 32548 KB Output is correct
3 Correct 351 ms 37616 KB Output is correct
4 Correct 345 ms 39544 KB Output is correct
5 Correct 348 ms 42580 KB Output is correct
6 Correct 335 ms 38508 KB Output is correct
7 Correct 282 ms 36616 KB Output is correct
8 Correct 209 ms 34520 KB Output is correct
9 Correct 238 ms 26448 KB Output is correct
10 Correct 309 ms 42584 KB Output is correct
11 Correct 255 ms 34864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 5 ms 5228 KB Output is correct
5 Correct 5 ms 5204 KB Output is correct
6 Correct 5 ms 5204 KB Output is correct
7 Correct 5 ms 5204 KB Output is correct
8 Correct 5 ms 5240 KB Output is correct
9 Correct 4 ms 5204 KB Output is correct
10 Correct 5 ms 5332 KB Output is correct
11 Correct 4 ms 5204 KB Output is correct
12 Correct 5 ms 5332 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 286 ms 31932 KB Output is correct
18 Correct 252 ms 35172 KB Output is correct
19 Correct 305 ms 38492 KB Output is correct
20 Correct 335 ms 39716 KB Output is correct
21 Correct 325 ms 39756 KB Output is correct
22 Correct 312 ms 36664 KB Output is correct
23 Correct 309 ms 42572 KB Output is correct
24 Correct 285 ms 32368 KB Output is correct
25 Correct 259 ms 35664 KB Output is correct
26 Correct 288 ms 34016 KB Output is correct
27 Correct 240 ms 35108 KB Output is correct
28 Correct 255 ms 35132 KB Output is correct
29 Correct 283 ms 36720 KB Output is correct
30 Correct 210 ms 35692 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 342 ms 36648 KB Output is correct
33 Correct 351 ms 41464 KB Output is correct
34 Correct 318 ms 36704 KB Output is correct
35 Correct 253 ms 34696 KB Output is correct
36 Correct 336 ms 41184 KB Output is correct
37 Correct 284 ms 36720 KB Output is correct
38 Correct 276 ms 36664 KB Output is correct
39 Correct 210 ms 35656 KB Output is correct
40 Correct 260 ms 34164 KB Output is correct
41 Correct 256 ms 34840 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 341 ms 32548 KB Output is correct
44 Correct 351 ms 37616 KB Output is correct
45 Correct 345 ms 39544 KB Output is correct
46 Correct 348 ms 42580 KB Output is correct
47 Correct 335 ms 38508 KB Output is correct
48 Correct 282 ms 36616 KB Output is correct
49 Correct 209 ms 34520 KB Output is correct
50 Correct 238 ms 26448 KB Output is correct
51 Correct 309 ms 42584 KB Output is correct
52 Correct 255 ms 34864 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 5 ms 5204 KB Output is correct
57 Correct 5 ms 5332 KB Output is correct
58 Correct 5 ms 5204 KB Output is correct
59 Correct 5 ms 5284 KB Output is correct
60 Correct 5 ms 5148 KB Output is correct
61 Correct 6 ms 5204 KB Output is correct
62 Correct 5 ms 5332 KB Output is correct
63 Correct 7 ms 5332 KB Output is correct
64 Correct 7 ms 5332 KB Output is correct
65 Correct 5 ms 5320 KB Output is correct
66 Correct 5 ms 5204 KB Output is correct
67 Correct 291 ms 36212 KB Output is correct
68 Correct 257 ms 35184 KB Output is correct
69 Correct 324 ms 38444 KB Output is correct
70 Correct 339 ms 39740 KB Output is correct
71 Correct 322 ms 39744 KB Output is correct
72 Correct 314 ms 36588 KB Output is correct
73 Correct 311 ms 42756 KB Output is correct
74 Correct 258 ms 32296 KB Output is correct
75 Correct 258 ms 35632 KB Output is correct
76 Correct 298 ms 34028 KB Output is correct
77 Correct 249 ms 35148 KB Output is correct
78 Correct 250 ms 35180 KB Output is correct
79 Correct 279 ms 36652 KB Output is correct
80 Correct 222 ms 35836 KB Output is correct
81 Correct 343 ms 41104 KB Output is correct
82 Correct 336 ms 41424 KB Output is correct
83 Correct 293 ms 36708 KB Output is correct
84 Correct 243 ms 34604 KB Output is correct
85 Correct 344 ms 41148 KB Output is correct
86 Correct 298 ms 36712 KB Output is correct
87 Correct 310 ms 36788 KB Output is correct
88 Correct 282 ms 34196 KB Output is correct
89 Correct 266 ms 34744 KB Output is correct
90 Correct 351 ms 36832 KB Output is correct
91 Correct 345 ms 37640 KB Output is correct
92 Correct 378 ms 39580 KB Output is correct
93 Correct 372 ms 42636 KB Output is correct
94 Correct 352 ms 38524 KB Output is correct
95 Correct 303 ms 36716 KB Output is correct
96 Correct 212 ms 34544 KB Output is correct
97 Correct 231 ms 26428 KB Output is correct
98 Correct 317 ms 42528 KB Output is correct
99 Correct 254 ms 34848 KB Output is correct
100 Correct 168 ms 18156 KB Output is correct
101 Correct 368 ms 38184 KB Output is correct
102 Correct 319 ms 34364 KB Output is correct
103 Correct 328 ms 32748 KB Output is correct
104 Correct 344 ms 35936 KB Output is correct