Submission #1002458

# Submission time Handle Problem Language Result Execution time Memory
1002458 2024-06-19T15:02:19 Z Andrey Stranded Far From Home (BOI22_island) C++17
0 / 100
78 ms 29020 KB
#include<bits/stdc++.h>
using namespace std;

vector<long long> haha[200001];
vector<long long> dsu(200001);
vector<long long> tree[200001];
vector<long long> st(200001);
vector<long long> wow(200001);
vector<bool> ans(200001);

long long calc(long long a) {
    long long c = a,e = a;
    while(dsu[c] != c) {
        c = dsu[c];
    }
    while(e != dsu[e]) {
        long long d = dsu[e];
        dsu[e] = c;
        e = d;
    }
    return c;
}

void dfs(long long a) {
    st[a] = wow[a];
    for(long long v: tree[a]) {
        dfs(v);
        st[a]+=st[v];
    }
}

void dude(long long a) {
    ans[a] = true;
    for(long long v: tree[a]) {
        if(st[v] >= wow[a]) {
            dude(v);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,m,a,b;
    cin >> n >> m;
    if(m != n-1) {
        cout << 1/0 << endl;
    }
    vector<pair<long long,long long>> wut(0);
    for(long long i = 1; i <= n; i++) {
        cin >> wow[i];
    }
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        if(b > a) {
            swap(a,b);
        }
        tree[a].push_back(b);
    }
 /* sort(wut.begin(),wut.end());
    for(long long i = 0; i < m; i++) {
        cin >> a >> b;
        if(wow[a] > wow[b]) {
            haha[a].push_back(b);
        }
        else {
            haha[b].push_back(a);
        }
    }
    for(long long i = 0; i < wut.size(); i++) {
        long long a = wut[i].second;
        for(long long v: haha[a]) {
            if(calc(v) != calc(a)) {
                tree[a].push_back(calc(v));
                dsu[calc(v)] = a;
            }
        }
    }*/
    dfs(1);
    dude(1);
    for(long long i = 1; i <= n; i++) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:49:18: warning: division by zero [-Wdiv-by-zero]
   49 |         cout << 1/0 << endl;
      |                 ~^~
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 29016 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 14372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Incorrect 78 ms 25348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Runtime error 15 ms 29020 KB Execution killed with signal 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 29016 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -