답안 #714682

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714682 2023-03-25T07:51:15 Z ismayil Stranded Far From Home (BOI22_island) C++17
20 / 100
1000 ms 351392 KB
#include <bits/stdc++.h>
#define int long long
//#define endl '\n'
using namespace std;
const int MAX = 2e5 + 5;
vector<int> adj[MAX];
int subtree[MAX], sum[MAX];
int s[MAX], ans[MAX], color[MAX];
void dfs_subtree(int u, int p){
    subtree[u] = s[u];
    for(auto v : adj[u]){
        if(v == p) continue;
        dfs_subtree(v, u);
        subtree[u] += subtree[v];
    }
}
void dfs(int u, int p){
    for(auto v : adj[u]){
        if(v == p) continue;
        if(subtree[v] < s[u]) continue;
        ans[v] = 1;
        dfs(v, u);
    }
}
bool bfs(int st){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.push(make_pair(s[st], st));
    while (!q.empty())
    {
        int u = q.top().second;
        int w = q.top().first;
        q.pop();
        color[u] = 1;
        if(w > sum[st] && st != u) return false;
        sum[st] += w;
        for(auto v : adj[u]){
            if(!color[v]) q.push({s[v], v});
        }

    }
    return true;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin>>n>>m;
    for(int i = 1; i <= n; i++) cin>>s[i];
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(n <= 2000){
        for(int i = 1; i <= n; i++){
            memset(color, 0, sizeof(color));
            cout<<bfs(i);
        }
        cout<<endl;
        return 0;
    }
    dfs_subtree(1, 0);
    dfs(1, 0);
    ans[1] = 1;
    for(int i = 1; i <= n; i++){
        cout<<ans[i];
    }
    cout<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6592 KB Output is correct
4 Correct 278 ms 6700 KB Output is correct
5 Correct 228 ms 6684 KB Output is correct
6 Correct 368 ms 6712 KB Output is correct
7 Correct 289 ms 6956 KB Output is correct
8 Correct 239 ms 6712 KB Output is correct
9 Correct 289 ms 6732 KB Output is correct
10 Correct 140 ms 6816 KB Output is correct
11 Correct 140 ms 6612 KB Output is correct
12 Correct 155 ms 6688 KB Output is correct
13 Correct 188 ms 6680 KB Output is correct
14 Correct 172 ms 6612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 145 ms 22116 KB Output is correct
4 Correct 131 ms 20732 KB Output is correct
5 Correct 160 ms 16692 KB Output is correct
6 Correct 169 ms 17012 KB Output is correct
7 Correct 172 ms 16992 KB Output is correct
8 Correct 182 ms 17228 KB Output is correct
9 Correct 136 ms 17600 KB Output is correct
10 Correct 85 ms 16192 KB Output is correct
11 Correct 91 ms 17720 KB Output is correct
12 Correct 171 ms 15772 KB Output is correct
13 Correct 124 ms 27084 KB Output is correct
14 Correct 128 ms 27180 KB Output is correct
15 Correct 151 ms 28620 KB Output is correct
16 Correct 78 ms 28396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Incorrect 148 ms 28644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Execution timed out 1084 ms 351392 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6592 KB Output is correct
4 Correct 278 ms 6700 KB Output is correct
5 Correct 228 ms 6684 KB Output is correct
6 Correct 368 ms 6712 KB Output is correct
7 Correct 289 ms 6956 KB Output is correct
8 Correct 239 ms 6712 KB Output is correct
9 Correct 289 ms 6732 KB Output is correct
10 Correct 140 ms 6816 KB Output is correct
11 Correct 140 ms 6612 KB Output is correct
12 Correct 155 ms 6688 KB Output is correct
13 Correct 188 ms 6680 KB Output is correct
14 Correct 172 ms 6612 KB Output is correct
15 Correct 4 ms 6484 KB Output is correct
16 Correct 3 ms 6484 KB Output is correct
17 Correct 145 ms 22116 KB Output is correct
18 Correct 131 ms 20732 KB Output is correct
19 Correct 160 ms 16692 KB Output is correct
20 Correct 169 ms 17012 KB Output is correct
21 Correct 172 ms 16992 KB Output is correct
22 Correct 182 ms 17228 KB Output is correct
23 Correct 136 ms 17600 KB Output is correct
24 Correct 85 ms 16192 KB Output is correct
25 Correct 91 ms 17720 KB Output is correct
26 Correct 171 ms 15772 KB Output is correct
27 Correct 124 ms 27084 KB Output is correct
28 Correct 128 ms 27180 KB Output is correct
29 Correct 151 ms 28620 KB Output is correct
30 Correct 78 ms 28396 KB Output is correct
31 Correct 4 ms 6484 KB Output is correct
32 Incorrect 148 ms 28644 KB Output isn't correct
33 Halted 0 ms 0 KB -