답안 #573736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573736 2022-06-07T06:33:35 Z kshitij_sodani Stranded Far From Home (BOI22_island) C++14
0 / 100
243 ms 29024 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define a first
#define b second
#define pb push_back
#define endl '\n'


int it[200001];
int n,m;
vector<int> adj[200001];
vector<pair<int,int>> adj2[200001];
int par[200001];
int ss[200001];
int find(int no){
	if(par[no]==no){
		return no;
	}
	par[no]=find(par[no]);
	return par[no];
}
int ans[200001];
void dfs(int no,int par=-1,int ma=0){
	ans[no]=1-ma;
	for(auto j:adj2[no]){
		dfs(j.a,no,max(ma,j.b));
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m;
	vector<pair<int,int>> tt;
	for(int i=0;i<n;i++){
		cin>>it[i];
		par[i]=i;
		ss[i]=it[i];
		tt.pb({it[i],i});
	}
	for(int i=0;i<m;i++){
		int aa,bb;
		cin>>aa>>bb;
		aa--;
		bb--;
		adj[aa].pb(bb);
		adj[bb].pb(aa);
	}
	sort(tt.begin(),tt.end());
	int ind=0;
	/*for(auto j:tt){
		cout<<j.a<<",";
	}
	cout<<endl;*/
	while(ind<tt.size()){
		int ind2=ind;
		while(ind<tt.size()){
			if(tt[ind].a==tt[ind2].a){
				ind++;
			}
			else{
				break;
			}
		}
		vector<int> ee;
		for(int i=ind2;i<ind;i++){
			ee.pb(tt[i].b);
		}

		for(auto j:ee){
			for(auto jj:adj[j]){
				if(it[jj]<it[j]){
					int x=find(jj);
					if(it[x]==it[j]){
						int y=find(j);
						if(x!=y){
							adj2[y].pb({x,0});
							par[x]=y;
							ss[y]+=ss[x];
						}
						continue;
					}
					int z=0;
					if(ss[x]<it[j]){
						z=1;
						//cout<<j<<":"<<x<<endl;
					}
					int y=find(j);
					if(x!=y){
						adj2[y].pb({x,z});
						par[x]=y;
						ss[y]+=ss[x];
					}
				}
			}
		}
		//cout<<ind2<<"::"<<ind<<endl;
		for(auto j:ee){
			for(auto jj:adj[j]){
				if(j==jj){
					continue;
				}
				if(it[jj]==it[j]){
					int x=find(j);
					int y=find(jj);

					if(x==y){
						continue;
					}
					//cout<<j<<"::"<<jj<<endl;
					par[x]=y;
					ss[y]+=ss[x];
					adj2[y].pb({x,0});
				}
			}
		}
		


	}
	dfs(find(0));
	for(int i=0;i<n;i++){
		cout<<ans[i];
	}
	cout<<endl;






	return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:55:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  while(ind<tt.size()){
      |        ~~~^~~~~~~~~~
island.cpp:57:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   while(ind<tt.size()){
      |         ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9648 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Incorrect 6 ms 9812 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9740 KB Output is correct
2 Correct 5 ms 9732 KB Output is correct
3 Incorrect 147 ms 29024 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 243 ms 25072 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Incorrect 209 ms 25624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9648 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Incorrect 6 ms 9812 KB Output isn't correct
5 Halted 0 ms 0 KB -