답안 #1024894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024894 2024-07-16T11:59:15 Z overwatch9 Stranded Far From Home (BOI22_island) C++17
0 / 100
795 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 1;
ll S[maxn];
vector <int> adj[maxn];
bool ans[maxn];
ll sz[maxn];
void dfs(int s, int p) {
    sz[s] = S[s];
    for (auto i : adj[s]) {
        if (i == p)
            continue;
        dfs(i, s);
        sz[s] += sz[i];
    }
}
vector <int> v;
void dfs2(int s, int p) {
    for (auto i : adj[s]) {
        if (i == p)
            continue;
        dfs2(i, s);
    }
    if (sz[s] >= S[p])
        v.push_back(s);
    else
        v.clear();
    if (p == 1) {
        if (sz[s] >= S[1]) {
            for (auto j : v)
                ans[j] = true;
        }
    }
}
int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> S[i];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1, 1);
    for (auto i : adj[1]) {
        dfs2(i, 1);
      	v.clear();
    }
    ans[1] = 1;
    for (int i = 1; i <= n; i++)
        cout << ans[i];
    cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 255 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 162 ms 24816 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Incorrect 178 ms 35000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Runtime error 795 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 255 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -