Submission #573739

# Submission time Handle Problem Language Result Execution time Memory
573739 2022-06-07T06:38:51 Z kshitij_sodani Stranded Far From Home (BOI22_island) C++14
0 / 100
1000 ms 24512 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;
		ans[i]=1;
		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(int i=0;i<n;i++){
			if(it[i]<tt[ind2].a){
				
				if(ss[find(i)]<tt[ind2].a){
					ans[i]=0;
				}
			}
		}
		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:56: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]
   56 |  while(ind<tt.size()){
      |        ~~~^~~~~~~~~~
island.cpp:58: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]
   58 |   while(ind<tt.size()){
      |         ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 16 ms 9844 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9728 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Execution timed out 1088 ms 21076 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Execution timed out 1083 ms 20624 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 228 ms 24512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 16 ms 9844 KB Output isn't correct
5 Halted 0 ms 0 KB -