답안 #948191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948191 2024-03-17T20:20:45 Z amirhoseinfar1385 Stranded Far From Home (BOI22_island) C++17
100 / 100
597 ms 68296 KB
#include<bits/stdc++.h>
using namespace std;
const long long maxn=200000+10;
vector<long long>adj[maxn];
long long all[maxn],n,m,dp[maxn],vis[maxn],mishe[maxn],mn[maxn];

struct cmp {
    bool operator() (long long a, long long b) const {
		if(all[a]==all[b]){
			return a<b;
		}
		return all[a]<all[b];
    }
};

struct dsu{
	long long par[maxn],sum[maxn],mx[maxn];
	set<long long,cmp>st[maxn];
	dsu(){
		for(long long i=0;i<maxn;i++){
			par[i]=i;
		}
	}
	long long root(long long u){
		if(u==par[u]){
			return u;
		}
		return par[u]=root(par[u]);
	}
	void con(long long u,long long v){
		long long rootu=root(u),rootv=root(v);
		if(rootu!=rootv){
			if((long long)st[rootu].size()<(long long)st[rootv].size()){
				swap(rootu,rootv);
			}
			par[rootv]=rootu;
			sum[rootu]+=sum[rootv];
			mx[rootu]=max(mx[rootu],mx[rootv]);
			for(auto x:st[rootv]){
				st[rootu].insert(x);
			}
			while((long long)st[rootu].size()>0&&mx[rootu]>=all[(*st[rootu].begin())]){
				st[rootu].erase(*st[rootu].begin());
			}
		}
	}
	long long porssum(long long u){
		long long v=root(u);
		return sum[v];
	}
	long long porsy(long long u){
		long long v=root(u);
		if((long long)st[v].size()==0){
			return -1;
		}
		return (*st[v].begin());
	}
}ds;

void vorod(){
	cin>>n>>m;
	all[0]=1e9+5;
	for(long long i=1;i<=n;i++){
		cin>>all[i];
		ds.sum[i]=all[i];
		ds.mx[i]=all[i];
	}
	for(long long i=0;i<m;i++){
		long long u,v;
		cin>>u>>v;
		//cout<<"ha "<<u<<" "<<v<<endl;
		ds.st[u].insert(v);
		ds.st[v].insert(u);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
}

void pre(){
	vector<pair<long long,long long>>so;
	for(long long i=1;i<=n;i++){
		so.push_back(make_pair(all[i],i));
	}
	sort(so.begin(),so.end());
	vector<long long>now;
	for(long long i=0;i<n;i++){
		if(i>0&&so[i].first!=so[i-1].first){
			for(auto x:now){
				dp[x]=ds.porssum(x);
				mn[x]=ds.porsy(x);
			}
			now.clear();
		}
		long long u=so[i].second;
		now.push_back(u);
		vis[u]=1;
		for(auto x:adj[u]){
			if(vis[x]==1){
				ds.con(x,u);
			}
		}
	}
	for(auto x:now){
		dp[x]=ds.porssum(x);
		mn[x]=ds.porsy(x);
	}
	now.clear();
}

void solve(){
	vector<pair<long long,long long>>so;
	for(long long i=1;i<=n;i++){
		so.push_back(make_pair(all[i],i));
	}
	sort(so.begin(),so.end());
	for(long long i=n-1;i>=0;i--){
		long long u=so[i].second;
		//cout<<u<<" "<<dp[u]<<" "<<mn[u]<<endl;
		if(all[u]==so.back().first){
			mishe[u]=1;
		}
		if(mn[u]==-1||mishe[mn[u]]==0||dp[u]<all[mn[u]]){
			mishe[u]|=0;
		}else{
			mishe[u]|=1;
		}
	}
	for(long long i=1;i<=n;i++){
		cout<<mishe[i];
	}
	cout<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen("inp.txt","r",stdin);
	vorod();
	pre();
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 26972 KB Output is correct
2 Correct 6 ms 26972 KB Output is correct
3 Correct 6 ms 26972 KB Output is correct
4 Correct 7 ms 27392 KB Output is correct
5 Correct 7 ms 27228 KB Output is correct
6 Correct 7 ms 27228 KB Output is correct
7 Correct 9 ms 27228 KB Output is correct
8 Correct 8 ms 27228 KB Output is correct
9 Correct 7 ms 27228 KB Output is correct
10 Correct 7 ms 27224 KB Output is correct
11 Correct 7 ms 27224 KB Output is correct
12 Correct 8 ms 27336 KB Output is correct
13 Correct 6 ms 27224 KB Output is correct
14 Correct 7 ms 27228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 282 ms 60408 KB Output is correct
4 Correct 275 ms 65188 KB Output is correct
5 Correct 381 ms 64212 KB Output is correct
6 Correct 357 ms 64672 KB Output is correct
7 Correct 348 ms 64568 KB Output is correct
8 Correct 376 ms 64888 KB Output is correct
9 Correct 344 ms 66120 KB Output is correct
10 Correct 395 ms 63912 KB Output is correct
11 Correct 458 ms 67372 KB Output is correct
12 Correct 350 ms 63700 KB Output is correct
13 Correct 286 ms 65244 KB Output is correct
14 Correct 295 ms 65408 KB Output is correct
15 Correct 276 ms 64820 KB Output is correct
16 Correct 161 ms 63920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 26972 KB Output is correct
2 Correct 380 ms 59300 KB Output is correct
3 Correct 386 ms 64048 KB Output is correct
4 Correct 297 ms 67100 KB Output is correct
5 Correct 280 ms 64796 KB Output is correct
6 Correct 348 ms 63768 KB Output is correct
7 Correct 305 ms 63796 KB Output is correct
8 Correct 288 ms 64668 KB Output is correct
9 Correct 127 ms 62964 KB Output is correct
10 Correct 280 ms 65432 KB Output is correct
11 Correct 309 ms 63620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 26972 KB Output is correct
2 Correct 462 ms 60448 KB Output is correct
3 Correct 426 ms 64648 KB Output is correct
4 Correct 454 ms 65832 KB Output is correct
5 Correct 385 ms 65976 KB Output is correct
6 Correct 406 ms 64184 KB Output is correct
7 Correct 382 ms 66664 KB Output is correct
8 Correct 183 ms 66208 KB Output is correct
9 Correct 476 ms 59632 KB Output is correct
10 Correct 386 ms 63864 KB Output is correct
11 Correct 343 ms 62876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 26972 KB Output is correct
2 Correct 6 ms 26972 KB Output is correct
3 Correct 6 ms 26972 KB Output is correct
4 Correct 7 ms 27392 KB Output is correct
5 Correct 7 ms 27228 KB Output is correct
6 Correct 7 ms 27228 KB Output is correct
7 Correct 9 ms 27228 KB Output is correct
8 Correct 8 ms 27228 KB Output is correct
9 Correct 7 ms 27228 KB Output is correct
10 Correct 7 ms 27224 KB Output is correct
11 Correct 7 ms 27224 KB Output is correct
12 Correct 8 ms 27336 KB Output is correct
13 Correct 6 ms 27224 KB Output is correct
14 Correct 7 ms 27228 KB Output is correct
15 Correct 6 ms 26972 KB Output is correct
16 Correct 5 ms 26972 KB Output is correct
17 Correct 282 ms 60408 KB Output is correct
18 Correct 275 ms 65188 KB Output is correct
19 Correct 381 ms 64212 KB Output is correct
20 Correct 357 ms 64672 KB Output is correct
21 Correct 348 ms 64568 KB Output is correct
22 Correct 376 ms 64888 KB Output is correct
23 Correct 344 ms 66120 KB Output is correct
24 Correct 395 ms 63912 KB Output is correct
25 Correct 458 ms 67372 KB Output is correct
26 Correct 350 ms 63700 KB Output is correct
27 Correct 286 ms 65244 KB Output is correct
28 Correct 295 ms 65408 KB Output is correct
29 Correct 276 ms 64820 KB Output is correct
30 Correct 161 ms 63920 KB Output is correct
31 Correct 5 ms 26972 KB Output is correct
32 Correct 380 ms 59300 KB Output is correct
33 Correct 386 ms 64048 KB Output is correct
34 Correct 297 ms 67100 KB Output is correct
35 Correct 280 ms 64796 KB Output is correct
36 Correct 348 ms 63768 KB Output is correct
37 Correct 305 ms 63796 KB Output is correct
38 Correct 288 ms 64668 KB Output is correct
39 Correct 127 ms 62964 KB Output is correct
40 Correct 280 ms 65432 KB Output is correct
41 Correct 309 ms 63620 KB Output is correct
42 Correct 5 ms 26972 KB Output is correct
43 Correct 462 ms 60448 KB Output is correct
44 Correct 426 ms 64648 KB Output is correct
45 Correct 454 ms 65832 KB Output is correct
46 Correct 385 ms 65976 KB Output is correct
47 Correct 406 ms 64184 KB Output is correct
48 Correct 382 ms 66664 KB Output is correct
49 Correct 183 ms 66208 KB Output is correct
50 Correct 476 ms 59632 KB Output is correct
51 Correct 386 ms 63864 KB Output is correct
52 Correct 343 ms 62876 KB Output is correct
53 Correct 6 ms 26972 KB Output is correct
54 Correct 5 ms 26972 KB Output is correct
55 Correct 5 ms 27068 KB Output is correct
56 Correct 7 ms 27228 KB Output is correct
57 Correct 7 ms 27228 KB Output is correct
58 Correct 7 ms 27228 KB Output is correct
59 Correct 7 ms 27228 KB Output is correct
60 Correct 7 ms 27228 KB Output is correct
61 Correct 8 ms 27228 KB Output is correct
62 Correct 7 ms 27228 KB Output is correct
63 Correct 7 ms 27320 KB Output is correct
64 Correct 7 ms 27228 KB Output is correct
65 Correct 6 ms 27228 KB Output is correct
66 Correct 8 ms 27228 KB Output is correct
67 Correct 285 ms 64788 KB Output is correct
68 Correct 323 ms 64476 KB Output is correct
69 Correct 334 ms 64132 KB Output is correct
70 Correct 340 ms 64660 KB Output is correct
71 Correct 327 ms 65672 KB Output is correct
72 Correct 365 ms 64756 KB Output is correct
73 Correct 337 ms 65908 KB Output is correct
74 Correct 357 ms 63932 KB Output is correct
75 Correct 393 ms 66988 KB Output is correct
76 Correct 361 ms 63456 KB Output is correct
77 Correct 266 ms 65056 KB Output is correct
78 Correct 262 ms 64740 KB Output is correct
79 Correct 260 ms 64500 KB Output is correct
80 Correct 136 ms 63316 KB Output is correct
81 Correct 338 ms 64756 KB Output is correct
82 Correct 346 ms 63848 KB Output is correct
83 Correct 268 ms 67284 KB Output is correct
84 Correct 252 ms 64196 KB Output is correct
85 Correct 362 ms 63864 KB Output is correct
86 Correct 266 ms 64432 KB Output is correct
87 Correct 294 ms 64520 KB Output is correct
88 Correct 266 ms 65256 KB Output is correct
89 Correct 313 ms 62872 KB Output is correct
90 Correct 439 ms 64872 KB Output is correct
91 Correct 459 ms 64956 KB Output is correct
92 Correct 458 ms 64932 KB Output is correct
93 Correct 370 ms 65808 KB Output is correct
94 Correct 329 ms 65240 KB Output is correct
95 Correct 389 ms 66604 KB Output is correct
96 Correct 190 ms 65652 KB Output is correct
97 Correct 443 ms 59556 KB Output is correct
98 Correct 374 ms 63332 KB Output is correct
99 Correct 320 ms 63076 KB Output is correct
100 Correct 253 ms 52312 KB Output is correct
101 Correct 453 ms 65012 KB Output is correct
102 Correct 349 ms 65068 KB Output is correct
103 Correct 597 ms 68296 KB Output is correct
104 Correct 573 ms 65212 KB Output is correct