답안 #971797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971797 2024-04-29T10:13:22 Z NintsiChkhaidze Stranded Far From Home (BOI22_island) C++17
0 / 100
235 ms 34996 KB
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define int long long
using namespace std;
 
const int N = 2e5 + 5;
int p[N],sz[N],ans[N];
pii b[N];
bool active[N];
vector <int> v[N],vec,cmp[N];
set <pii> st;

int P(int x){
	if(x==p[x]) return x;
	return p[x]=P(p[x]);
}

void dsu(int x,int y){
	int px=P(x),py=P(y);
	if (px==py) return;

	st.erase(st.find({sz[px],px}));
	st.erase(st.find({sz[py],py}));
	
	if (cmp[px].size() < cmp[py].size()) swap(px,py);
	sz[px] += sz[py];
	for (int k: cmp[py])
		cmp[px].pb(k);

	cmp[py].clear();
	sz[py]=0;
	st.insert({sz[px],px});
	p[py] = px;
}

void go(int x){
	active[x] = 1;
	st.insert({sz[x],x});
	for (int to: v[x]){
		if (active[to] && ans[to]) {
			dsu(x,to);
		}
	}
}

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
 
	int n,m;
	cin>>n>>m;	

	for (int i = 1; i <= n; i++){
		int a;
		cin>>a;
		sz[i] = a;
		p[i] = i;
		cmp[i].pb(i);
		b[i] = {a,i};
		vec.pb(a);
		ans[i]=1;
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());

	sort(b+1,b+n+1);

	for (int i=1;i<=m;i++){
		int a,bb;
		cin>>a>>bb;
		v[a].pb(bb);
		v[bb].pb(a);
	}

	int l = 1;
	for (int i=0;i<vec.size();i++){
		int val=vec[i];
		while (l <= n && b[l].f == val){
			go(b[l].s);
			++l;
		}

		if (i + 1 < vec.size()){
			int nxt = vec[i + 1];
			while (st.size() && (st.begin()->f) < nxt){
				int vert = st.begin()->s;
				for (int y: cmp[vert])
					ans[y]=0;
				st.erase(st.begin());
			}
		}
	}

	for (int i=1;i<=n;i++)
		cout<<ans[i];
}	

Compilation message

island.cpp: In function 'int main()':
island.cpp:78:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |  for (int i=0;i<vec.size();i++){
      |               ~^~~~~~~~~~~
island.cpp:85:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   if (i + 1 < vec.size()){
      |       ~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Incorrect 4 ms 14940 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Incorrect 131 ms 34752 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Incorrect 186 ms 31864 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Incorrect 235 ms 34996 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Incorrect 4 ms 14940 KB Output isn't correct
5 Halted 0 ms 0 KB -