답안 #972100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972100 2024-04-30T05:22:10 Z Nare_2007 Stranded Far From Home (BOI22_island) C++17
0 / 100
871 ms 524288 KB
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <string>
#define ll long long
using namespace std;
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
#define lli long long int 

vector<ll> g[200005];
ll dp[200005], a[200005];
vector<ll> ans(200005, 0);
bool vis[200005];

void dfs1(ll v, ll p) {
	if (g[v].size() == 1) {
		dp[v] = a[v];
		return;
	}
	for (auto x : g[v]) {
		if (x == p) {
			continue;
		}
		dfs1(x, v);
		dp[v] += dp[x];
	}
	dp[v] += a[v];
}

void solve() {
	ll n, m;
	cin >> n >> m;
	for (ll i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (ll i = 0; i < m; ++i) {
		ll x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs1(1, 0);
	queue<ll> q;
	q.push(1);
	vis[1] = 1;
	ans[1] = 1;
	while (!q.empty()) {
		ll k = q.front();
		q.pop();
		for (auto x : g[k]) {
			if (!vis[x]) {
				vis[x] = 1;
				q.push(x);
				if (dp[x] >= a[k]) {
					ans[x] = 1;
				}
			}
		}
	}
	for (ll i = 1; i <= n; ++i) {
		cout << ans[i];
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 296 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 3 ms 9816 KB Output is correct
3 Correct 95 ms 22308 KB Output is correct
4 Incorrect 90 ms 25372 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9816 KB Output is correct
2 Incorrect 77 ms 16216 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Runtime error 871 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 296 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -