답안 #966424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966424 2024-04-19T20:31:31 Z NotLinux Stranded Far From Home (BOI22_island) C++17
0 / 100
174 ms 29072 KB
//author : FatihCihan
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
const int N = 2e5 + 7;
const int inf = 1e9 + 7;
int n,m,s[N],ans[N],mem_value[N],mem_par[N],tar[N];
vector < int > graph[N] , adj[N];

int par[N] , value[N] , mx[N];
int find(int a){
	if(par[a] == a)return a;
	else return par[a] = find(par[a]);
}
void merge(int a , int b){
	a = find(a) , b = find(b);
	if(a == b)return;
	value[b] += value[a];
	par[a] = b;
	if(s[mx[a]] > s[mx[b]])mx[b] = mx[a];
}

void solve(){
	cin >> n >> m;
	pair < int , int > village[n];
	vector < int > compr;
	for(int i = 1;i<=n;i++){
		cin >> s[i];
		village[i-1] = {s[i] , i};
		tar[i] = inf;
		par[i] = mx[i] = i , value[i] = s[i];
		compr.push_back(s[i]);
	}
	sort(all(compr));
	compr.resize(unique(all(compr)) - compr.begin());
	sort(village , village + n);
	for(int i = 0;i<m;i++){
		int ai,bi;
		cin >> ai >> bi;
		graph[ai].push_back(bi);
		graph[bi].push_back(ai);
	}
	int lp = 0;
	for(auto si : compr){
		// cout << "		SI : " << si << endl;
		vector < int > v;
		while(lp < n and s[village[lp].second] <= si){
			v.push_back(village[lp].second);
			lp++;
		}
		vector < pair < int , int > > gh;
		for(auto node : v){
			for(auto itr : graph[node]){
				if(s[itr] < s[node]){
					gh.push_back({node , mx[find(itr)]});
				}
			}
		}
		for(auto node : v){
			for(auto itr : graph[node]){
				if(s[itr] <= s[node]){
					merge(itr , node);
				}
			}
		}
		for(auto itr : gh){
			adj[find(itr.first)].push_back(itr.second);
		}
		for(auto node : v){
			mem_value[node] = value[find(node)];
			mem_par[node] = find(node);
			// cout << node << " : " << mem_value[node] << " , " << mem_par[node] << endl;
		}
	}
	// cout << "		ENDED" << endl;
	for(int i = 1;i<=n;i++){
		sort(all(adj[i]));
		adj[i].resize(unique(all(adj[i])) - adj[i].begin());
	}
	int mx_s = village[n-1].first;
	for(int i = 1;i<=n;i++){
		if(s[i] == mx_s){
			tar[i] = 0;
		}
	}
	for(int i = n-1;i>=0;i--){
		// cout << "equal : " << village[i].second << " " <<  mem_par[village[i].second] << endl;
		// cout << "values : " << tar[village[i].second] << " " << mem_value[village[i].second] << endl;
		// cout << endl;
		if(mem_par[village[i].second] != village[i].second)continue;
		else if(tar[village[i].second] <= mem_value[village[i].second]){
			ans[village[i].second] = 1;
			// cout << "adj " << village[i].second << " : ";
			for(auto itr : adj[village[i].second]){
				// cout << itr << " ";
				tar[itr] = min(tar[itr] , s[village[i].second]);
			}
			// cout << endl;
		}
		else{
			ans[village[i].second] = 0;
		}
	}
	for(int i = 1;i<=n;i++){
		cout << ans[mem_par[i]];
	}
	cout << endl;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
	// cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14780 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14684 KB Output is correct
4 Incorrect 5 ms 14936 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14684 KB Output is correct
2 Correct 4 ms 14684 KB Output is correct
3 Incorrect 109 ms 29072 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Incorrect 174 ms 28880 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Incorrect 146 ms 27856 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14780 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14684 KB Output is correct
4 Incorrect 5 ms 14936 KB Output isn't correct
5 Halted 0 ms 0 KB -