답안 #919076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919076 2024-01-31T08:12:57 Z Isam Stranded Far From Home (BOI22_island) C++17
컴파일 오류
0 ms 0 KB
#include<iostream>
#include<vector>
using namespace std;

const int sz=200005;

int n, m, sizel[sz], fa[sz];
int folk[sz], sm[sz];

bool ans[sz];

inline void init(){
	for(int i=1; i<=n; ++i) sizel[i]=1, fa[i]=i, ans[i]=true;
	return;
}
int find_set(int &v){
    if(fa[v] == v)
        return v;
       if(!ans[fa[v]]) ans[v]=0;
    return fa[v]=find_set(fa[v]);
}


	

//b->a

bool Union(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if(a ^ b){
        if(folk[a]<folk[b]) swap(a,b);
        if(folk[a]>sm[b]) ans[b]=0;
        fa[b]=a;
        sm[a]+=sm[b];
        
        return true;
    }
    return false;
}

struct edge{
	int a, b;
	int maxf;
	
	
	
};

bool cmp(edge e1, edge e2){
	return e1.maxf<e2.maxf;
}



vector<edge> e;

int a, b, maxf;

inline void Solution(){
	cin>>n>>m;
	init();
	for(int i=1; i<=n; ++i){
		cin>>folk[i];
	}
	
	
	for(int i=1; i<=m; ++i){
		cin>>a>>b;
		e.emplace_back((edge){a,b,max(folk[a], folk[b])});
	}
	sort(e.begin(), e.end(), cmp);
	
	for(int i=0; i<m; ++i){
		Union(e[i].a, e[i].b);
		
	}
	
	for(int i=1; i<=n; ++i) cout<<!ans[i];
	
	
	return;
	
}
int main(){
    ios_base::sync_with_stdio(false);
    Solution();
    return 0;
}






Compilation message

island.cpp: In function 'void Solution()':
island.cpp:72:2: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   72 |  sort(e.begin(), e.end(), cmp);
      |  ^~~~
      |  qsort