Submission #877763

# Submission time Handle Problem Language Result Execution time Memory
877763 2023-11-23T14:11:44 Z vjudge1 Stranded Far From Home (BOI22_island) C++17
0 / 100
484 ms 45404 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

using ll = long long;
using ld = long double;
 
void solve(int T);
void pre();
 
const int N = 2e5 + 10;
const int M = 405;
const int SQRT = 500;
const int LOG = 20;
const int INF = 1e18;
const int MOD = 1e9+7;
const ld EPS = 1e-9;

void pre(){
	#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);
	#endif
	
}

int32_t main(){
	pre();
	int tt = 1;
	//cin>>tt;
	for(int i = 1;i<=tt;i++){
		//cerr<<"Case "<<i<<": "<<endl;
		solve(i);
	}
    return 0;
}

int A[N];
vector<int> g[N];

bool vis[N];
int sum = 0;
vector<int> cur;

int xx;

void dfs(int x){
	vis[x] = true;
	sum += A[x];
	cur.pb(x);
	for(auto p: g[x]){
		if(vis[p])continue;
		if(A[p] <= xx)dfs(p);
	}
}

bool ok[N];

void solve(int T){
    int n,m;
	cin>>n>>m;
	set<int> s;
	for(int i = 1;i<=n;i++){
		cin>>A[i];
		s.insert(A[i]);
	}
	for(int i = 0;i<m;i++){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}

	memset(ok, 1, sizeof ok);

	int z = s.size();
	for(int i = 0;i < z - 1;i++){
		if(s.empty())break;
		auto in = *(s.begin());
		s.erase(in);
		if(s.empty())break;
		xx = in;
		for(int j = 1;j<=n;j++){
			for(auto p : g[j]){
				if(A[j] == i || A[p] == i){
					g[p].pb(j);
					g[j].pb(p);
				}
			}
		}

		memset(vis, 0, sizeof vis);
		for(int j = 1;j<=n;j++){
			if(!vis[j] && A[j] <= xx){
				sum = 0;
				cur.clear();
				dfs(j);

				if(sum < *(s.begin())){
					for(auto p : cur){
						ok[p] = false;
					}
				}
			}
		}
	}

	for(int i = 1;i<=n;i++)cout<< ok[i];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Runtime error 6 ms 13144 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 13148 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Runtime error 484 ms 45404 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 265 ms 14724 KB Output is correct
3 Correct 265 ms 14420 KB Output is correct
4 Correct 311 ms 14368 KB Output is correct
5 Correct 173 ms 14408 KB Output is correct
6 Correct 191 ms 14164 KB Output is correct
7 Correct 180 ms 17852 KB Output is correct
8 Runtime error 151 ms 44420 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Runtime error 6 ms 13144 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -