답안 #604021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604021 2022-07-24T15:25:58 Z l_reho Stranded Far From Home (BOI22_island) C++14
0 / 100
1000 ms 13212 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long

struct info{
	int node;
	ll people;
	
	bool operator <(const info &i) const{
		return people > i.people;
	}
	
};

int N, M;

vector<ll> A;
vector<bool> taken;
vector<vector<int>> graph;

void solve(){
	cin>>N>>M;
	
	A.assign(N, 0);
	graph.assign(N, vector<int>());
	
	for(ll &v:A) cin>>v;
	
	for(int i = 0; i < M; i++){
		int a, b;
		cin>>a>>b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
		
	}
	vector<bool> ans(N, 1);
	
	
	for(int color = 0; color < N; color++){
		priority_queue<info> pq;
		// inizializzo la pq
		vector<int> adj = graph[color];
		
		taken.assign(N, false);
		taken[color] = true;
		
		for(int a : adj)
			pq.push({a, A[a]});
		
		ll total = A[color];
		
		while(!pq.empty()){
			info i = pq.top();
			
			pq.pop();
			
			int node = i.node;
			taken[node] = true;
			ll abitants = i.people;
			
			if(abitants > total){
				ans[color] = 0;
				break;
			}
			total += abitants;
			vector<int> adj = graph[node];
			
			for(int a : adj){
				if(taken[a]) continue;
				pq.push({a, A[a]});
			}
			
		}	
	}
	
	for(int i = 0; i < N; i++) cout<<ans[i]<<" ";
	cout<<endl;
	
}

int main(){
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1081 ms 12668 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1076 ms 13212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -