Submission #581877

# Submission time Handle Problem Language Result Execution time Memory
581877 2022-06-23T07:37:40 Z temporary_juggernaut Stranded Far From Home (BOI22_island) C++14
100 / 100
199 ms 26204 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
    #define printl(args...) printf(args)
#else
    #define printl(args...) 0
#endif
ll a[200005];
int par[200005];
ll sum[200005];
vector<int>comp[200005];
ll mx[200005];
pair<int,int>edge[200005];
int n,m;
int cash=1;
bool cmp(pair<int,int>l,pair<int,int>r){
	if(a[l.fr]==a[r.fr])return a[l.sc]<a[r.sc];
	return a[l.fr]<a[r.fr];
}
int fin(int v){return (v==par[v])?v:par[v]=fin(par[v]);}
void unite(int a,int b){
	a=fin(a);
	b=fin(b);
	if(a==b)return;
	if(comp[a].size()<comp[b].size())swap(a,b);
	if(sum[a]<mx[b])comp[a].clear();
	if(sum[b]<mx[a])comp[b].clear();
	par[b]=a;
	umax(mx[a],mx[b]);
	sum[a]+=sum[b];
	cash=a;
	comp[a].insert(comp[a].end(),comp[b].begin(),comp[b].end());
	comp[b].clear();
}
int ans[200005];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		mx[i]=a[i];
		sum[i]=a[i];
		comp[i].push_back(i);
		par[i]=i;
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&edge[i].fr,&edge[i].sc);
		if(a[edge[i].fr]<a[edge[i].sc])swap(edge[i].fr,edge[i].sc);
	}
	sort(edge+1,edge+1+m,cmp);
	for(int i=1;i<=m;i++)unite(edge[i].fr,edge[i].sc);
	for(int to:comp[cash])ans[to]=1;
	for(int i=1;i<=n;i++)printf("%d",ans[i]);
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
island.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   scanf("%lld",&a[i]);
      |   ~~~~~^~~~~~~~~~~~~~
island.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%d%d",&edge[i].fr,&edge[i].sc);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4960 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 5116 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 5 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 6 ms 5128 KB Output is correct
9 Correct 4 ms 5160 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 4 ms 5204 KB Output is correct
12 Correct 3 ms 5204 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 5 ms 5076 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 144 ms 20252 KB Output is correct
4 Correct 170 ms 25012 KB Output is correct
5 Correct 143 ms 21528 KB Output is correct
6 Correct 163 ms 22060 KB Output is correct
7 Correct 160 ms 22180 KB Output is correct
8 Correct 166 ms 23952 KB Output is correct
9 Correct 139 ms 23212 KB Output is correct
10 Correct 126 ms 18420 KB Output is correct
11 Correct 135 ms 20088 KB Output is correct
12 Correct 157 ms 20428 KB Output is correct
13 Correct 167 ms 25868 KB Output is correct
14 Correct 163 ms 24884 KB Output is correct
15 Correct 151 ms 20148 KB Output is correct
16 Correct 119 ms 19960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 164 ms 23084 KB Output is correct
3 Correct 190 ms 22704 KB Output is correct
4 Correct 185 ms 26204 KB Output is correct
5 Correct 172 ms 25840 KB Output is correct
6 Correct 173 ms 23132 KB Output is correct
7 Correct 148 ms 20180 KB Output is correct
8 Correct 134 ms 20244 KB Output is correct
9 Correct 100 ms 20000 KB Output is correct
10 Correct 133 ms 19680 KB Output is correct
11 Correct 156 ms 23148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 175 ms 20840 KB Output is correct
3 Correct 174 ms 21196 KB Output is correct
4 Correct 177 ms 22072 KB Output is correct
5 Correct 171 ms 23000 KB Output is correct
6 Correct 159 ms 20856 KB Output is correct
7 Correct 146 ms 20212 KB Output is correct
8 Correct 110 ms 21856 KB Output is correct
9 Correct 95 ms 13764 KB Output is correct
10 Correct 165 ms 23328 KB Output is correct
11 Correct 148 ms 22888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4960 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 5116 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 5 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 6 ms 5128 KB Output is correct
9 Correct 4 ms 5160 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 4 ms 5204 KB Output is correct
12 Correct 3 ms 5204 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 5 ms 5076 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 144 ms 20252 KB Output is correct
18 Correct 170 ms 25012 KB Output is correct
19 Correct 143 ms 21528 KB Output is correct
20 Correct 163 ms 22060 KB Output is correct
21 Correct 160 ms 22180 KB Output is correct
22 Correct 166 ms 23952 KB Output is correct
23 Correct 139 ms 23212 KB Output is correct
24 Correct 126 ms 18420 KB Output is correct
25 Correct 135 ms 20088 KB Output is correct
26 Correct 157 ms 20428 KB Output is correct
27 Correct 167 ms 25868 KB Output is correct
28 Correct 163 ms 24884 KB Output is correct
29 Correct 151 ms 20148 KB Output is correct
30 Correct 119 ms 19960 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 164 ms 23084 KB Output is correct
33 Correct 190 ms 22704 KB Output is correct
34 Correct 185 ms 26204 KB Output is correct
35 Correct 172 ms 25840 KB Output is correct
36 Correct 173 ms 23132 KB Output is correct
37 Correct 148 ms 20180 KB Output is correct
38 Correct 134 ms 20244 KB Output is correct
39 Correct 100 ms 20000 KB Output is correct
40 Correct 133 ms 19680 KB Output is correct
41 Correct 156 ms 23148 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 175 ms 20840 KB Output is correct
44 Correct 174 ms 21196 KB Output is correct
45 Correct 177 ms 22072 KB Output is correct
46 Correct 171 ms 23000 KB Output is correct
47 Correct 159 ms 20856 KB Output is correct
48 Correct 146 ms 20212 KB Output is correct
49 Correct 110 ms 21856 KB Output is correct
50 Correct 95 ms 13764 KB Output is correct
51 Correct 165 ms 23328 KB Output is correct
52 Correct 148 ms 22888 KB Output is correct
53 Correct 2 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 5076 KB Output is correct
58 Correct 4 ms 5076 KB Output is correct
59 Correct 5 ms 5076 KB Output is correct
60 Correct 4 ms 5148 KB Output is correct
61 Correct 4 ms 5204 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 6 ms 5204 KB Output is correct
64 Correct 4 ms 5204 KB Output is correct
65 Correct 4 ms 5184 KB Output is correct
66 Correct 4 ms 5076 KB Output is correct
67 Correct 128 ms 19948 KB Output is correct
68 Correct 161 ms 25092 KB Output is correct
69 Correct 146 ms 21592 KB Output is correct
70 Correct 146 ms 22080 KB Output is correct
71 Correct 150 ms 22184 KB Output is correct
72 Correct 176 ms 23848 KB Output is correct
73 Correct 135 ms 23268 KB Output is correct
74 Correct 125 ms 18368 KB Output is correct
75 Correct 157 ms 20172 KB Output is correct
76 Correct 161 ms 20448 KB Output is correct
77 Correct 178 ms 26008 KB Output is correct
78 Correct 156 ms 24796 KB Output is correct
79 Correct 139 ms 20084 KB Output is correct
80 Correct 105 ms 19952 KB Output is correct
81 Correct 169 ms 22976 KB Output is correct
82 Correct 174 ms 22732 KB Output is correct
83 Correct 171 ms 26196 KB Output is correct
84 Correct 157 ms 25796 KB Output is correct
85 Correct 199 ms 23024 KB Output is correct
86 Correct 133 ms 20096 KB Output is correct
87 Correct 134 ms 20068 KB Output is correct
88 Correct 131 ms 19780 KB Output is correct
89 Correct 175 ms 23236 KB Output is correct
90 Correct 170 ms 20728 KB Output is correct
91 Correct 169 ms 21228 KB Output is correct
92 Correct 159 ms 21964 KB Output is correct
93 Correct 186 ms 22944 KB Output is correct
94 Correct 157 ms 21048 KB Output is correct
95 Correct 140 ms 20100 KB Output is correct
96 Correct 121 ms 21804 KB Output is correct
97 Correct 97 ms 13784 KB Output is correct
98 Correct 169 ms 23280 KB Output is correct
99 Correct 185 ms 23080 KB Output is correct
100 Correct 80 ms 6860 KB Output is correct
101 Correct 172 ms 21512 KB Output is correct
102 Correct 137 ms 18104 KB Output is correct
103 Correct 147 ms 17824 KB Output is correct
104 Correct 169 ms 20208 KB Output is correct