Submission #642462

# Submission time Handle Problem Language Result Execution time Memory
642462 2022-09-19T13:47:09 Z CattlemansRanch Stranded Far From Home (BOI22_island) C++14
100 / 100
136 ms 25828 KB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
const int MAXN=200005;
int par[MAXN];
long long a[MAXN];
vector<int> all[MAXN];
vector<piii> edges;

int find(int x){
	if(par[x]==x)return par[x];
	return par[x]=find(par[x]);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,m,u,v;
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		par[i]=i;
		all[i].push_back(i);
	}
	for(int i=1;i<=m;i++){
		cin >> u >> v;
		if(a[u]>a[v])edges.push_back({a[u],{u,v}});
		else edges.push_back({a[v],{v,u}});
	}
	sort(edges.begin(),edges.end());
	for(auto isi : edges){
		int aa=find(isi.second.first),bb=find(isi.second.second);
		if(aa==bb)continue;
		if(a[bb]>=isi.first){
			if(all[aa].size()<all[bb].size())all[aa].swap(all[bb]);
			for(auto isi : all[bb])all[aa].push_back(isi);
		}
		a[aa]+=a[bb];
		par[bb]=aa;
	}
	string ans="";
	for(int i=0;i<n;i++)ans+='0';
	for(auto isi : all[find(1)]){
		ans[isi-1]='1';
	}
	cout << ans << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4912 KB Output is correct
4 Correct 4 ms 5164 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 4 ms 5140 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 4 ms 5164 KB Output is correct
12 Correct 3 ms 5204 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 4 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5032 KB Output is correct
2 Correct 2 ms 4920 KB Output is correct
3 Correct 102 ms 22108 KB Output is correct
4 Correct 95 ms 21600 KB Output is correct
5 Correct 109 ms 23200 KB Output is correct
6 Correct 112 ms 23772 KB Output is correct
7 Correct 122 ms 23920 KB Output is correct
8 Correct 112 ms 22308 KB Output is correct
9 Correct 96 ms 25716 KB Output is correct
10 Correct 86 ms 20136 KB Output is correct
11 Correct 94 ms 21296 KB Output is correct
12 Correct 112 ms 20736 KB Output is correct
13 Correct 83 ms 22144 KB Output is correct
14 Correct 89 ms 22096 KB Output is correct
15 Correct 93 ms 22420 KB Output is correct
16 Correct 72 ms 21508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 116 ms 24484 KB Output is correct
3 Correct 117 ms 24684 KB Output is correct
4 Correct 91 ms 23728 KB Output is correct
5 Correct 84 ms 21464 KB Output is correct
6 Correct 117 ms 24812 KB Output is correct
7 Correct 95 ms 22432 KB Output is correct
8 Correct 93 ms 22444 KB Output is correct
9 Correct 73 ms 21608 KB Output is correct
10 Correct 95 ms 22140 KB Output is correct
11 Correct 102 ms 21240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 133 ms 22520 KB Output is correct
3 Correct 124 ms 22920 KB Output is correct
4 Correct 136 ms 23900 KB Output is correct
5 Correct 132 ms 25364 KB Output is correct
6 Correct 124 ms 23044 KB Output is correct
7 Correct 98 ms 23644 KB Output is correct
8 Correct 83 ms 21412 KB Output is correct
9 Correct 78 ms 15192 KB Output is correct
10 Correct 128 ms 24548 KB Output is correct
11 Correct 108 ms 21160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4912 KB Output is correct
4 Correct 4 ms 5164 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 4 ms 5140 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 4 ms 5164 KB Output is correct
12 Correct 3 ms 5204 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 4 ms 5152 KB Output is correct
15 Correct 3 ms 5032 KB Output is correct
16 Correct 2 ms 4920 KB Output is correct
17 Correct 102 ms 22108 KB Output is correct
18 Correct 95 ms 21600 KB Output is correct
19 Correct 109 ms 23200 KB Output is correct
20 Correct 112 ms 23772 KB Output is correct
21 Correct 122 ms 23920 KB Output is correct
22 Correct 112 ms 22308 KB Output is correct
23 Correct 96 ms 25716 KB Output is correct
24 Correct 86 ms 20136 KB Output is correct
25 Correct 94 ms 21296 KB Output is correct
26 Correct 112 ms 20736 KB Output is correct
27 Correct 83 ms 22144 KB Output is correct
28 Correct 89 ms 22096 KB Output is correct
29 Correct 93 ms 22420 KB Output is correct
30 Correct 72 ms 21508 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 116 ms 24484 KB Output is correct
33 Correct 117 ms 24684 KB Output is correct
34 Correct 91 ms 23728 KB Output is correct
35 Correct 84 ms 21464 KB Output is correct
36 Correct 117 ms 24812 KB Output is correct
37 Correct 95 ms 22432 KB Output is correct
38 Correct 93 ms 22444 KB Output is correct
39 Correct 73 ms 21608 KB Output is correct
40 Correct 95 ms 22140 KB Output is correct
41 Correct 102 ms 21240 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 133 ms 22520 KB Output is correct
44 Correct 124 ms 22920 KB Output is correct
45 Correct 136 ms 23900 KB Output is correct
46 Correct 132 ms 25364 KB Output is correct
47 Correct 124 ms 23044 KB Output is correct
48 Correct 98 ms 23644 KB Output is correct
49 Correct 83 ms 21412 KB Output is correct
50 Correct 78 ms 15192 KB Output is correct
51 Correct 128 ms 24548 KB Output is correct
52 Correct 108 ms 21160 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 4 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 4 ms 5164 KB Output is correct
59 Correct 5 ms 5076 KB Output is correct
60 Correct 3 ms 5092 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 4 ms 5204 KB Output is correct
64 Correct 4 ms 5204 KB Output is correct
65 Correct 3 ms 5076 KB Output is correct
66 Correct 4 ms 5152 KB Output is correct
67 Correct 99 ms 22088 KB Output is correct
68 Correct 91 ms 21628 KB Output is correct
69 Correct 109 ms 23176 KB Output is correct
70 Correct 110 ms 23800 KB Output is correct
71 Correct 108 ms 23908 KB Output is correct
72 Correct 115 ms 22324 KB Output is correct
73 Correct 101 ms 25828 KB Output is correct
74 Correct 85 ms 20116 KB Output is correct
75 Correct 89 ms 21348 KB Output is correct
76 Correct 107 ms 20640 KB Output is correct
77 Correct 84 ms 22088 KB Output is correct
78 Correct 95 ms 22128 KB Output is correct
79 Correct 95 ms 22360 KB Output is correct
80 Correct 71 ms 21596 KB Output is correct
81 Correct 118 ms 24552 KB Output is correct
82 Correct 122 ms 24828 KB Output is correct
83 Correct 102 ms 23732 KB Output is correct
84 Correct 82 ms 21444 KB Output is correct
85 Correct 117 ms 24740 KB Output is correct
86 Correct 91 ms 22332 KB Output is correct
87 Correct 100 ms 22424 KB Output is correct
88 Correct 95 ms 22148 KB Output is correct
89 Correct 95 ms 21156 KB Output is correct
90 Correct 125 ms 22528 KB Output is correct
91 Correct 127 ms 23072 KB Output is correct
92 Correct 129 ms 23864 KB Output is correct
93 Correct 133 ms 25392 KB Output is correct
94 Correct 135 ms 23100 KB Output is correct
95 Correct 103 ms 23644 KB Output is correct
96 Correct 80 ms 21340 KB Output is correct
97 Correct 80 ms 15312 KB Output is correct
98 Correct 133 ms 24532 KB Output is correct
99 Correct 103 ms 21196 KB Output is correct
100 Correct 61 ms 9900 KB Output is correct
101 Correct 125 ms 23236 KB Output is correct
102 Correct 116 ms 20252 KB Output is correct
103 Correct 112 ms 20000 KB Output is correct
104 Correct 125 ms 22084 KB Output is correct