Submission #694977

# Submission time Handle Problem Language Result Execution time Memory
694977 2023-02-04T16:11:45 Z finn__ Stranded Far From Home (BOI22_island) C++17
10 / 100
246 ms 13404 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    size_t n, m;
    cin >> n >> m;

    vector<uint64_t> s(n);
    uint64_t total_size = 0;
    for (uint64_t &x : s)
        cin >> x, total_size += x;

    vector<vector<unsigned>> g(n);
    for (size_t i = 0; i < m; i++)
    {
        unsigned u, v;
        cin >> u >> v;
        g[u - 1].push_back(v - 1);
        g[v - 1].push_back(u - 1);
    }

    if (n > 2000)
    {
        unsigned presum = s[n - 1];
        string y;
        y.resize(n);
        for (size_t i = n - 1; i < n; i--)
        {
            if (!i || presum >= s[i - 1])
                y[i] = '1';
            else
                y[i] = '0';
            presum += i ? s[i - 1] : 0;
        }
        cout << y << '\n';
        return 0;
    }

    vector<bool> z(n, 0);

    for (unsigned i = 0; i < n; i++)
    {
        priority_queue<pair<unsigned, unsigned>, vector<pair<unsigned, unsigned>>, greater<pair<unsigned, unsigned>>> q;
        vector<bool> visited(n, 0);
        visited[i] = 1;
        uint64_t curr_size = s[i];
        for (unsigned const &v : g[i])
            q.emplace(s[v], v), visited[v] = 1;

        while (!q.empty())
        {
            auto const [x, u] = q.top();
            q.pop();
            if (x > curr_size)
                break;
            curr_size += x;
            for (unsigned const &v : g[u])
                if (!visited[v])
                {
                    q.emplace(s[v], v);
                    visited[v] = 1;
                }
        }

        z[i] = curr_size == total_size;
    }

    for (size_t i = 0; i < n; i++)
        cout << (unsigned)z[i];
    cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 145 ms 440 KB Output is correct
5 Correct 147 ms 444 KB Output is correct
6 Correct 178 ms 412 KB Output is correct
7 Correct 143 ms 420 KB Output is correct
8 Correct 102 ms 340 KB Output is correct
9 Correct 194 ms 440 KB Output is correct
10 Correct 56 ms 340 KB Output is correct
11 Correct 53 ms 340 KB Output is correct
12 Correct 59 ms 440 KB Output is correct
13 Correct 101 ms 420 KB Output is correct
14 Correct 102 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 244 ms 13404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 233 ms 13248 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 246 ms 13324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 145 ms 440 KB Output is correct
5 Correct 147 ms 444 KB Output is correct
6 Correct 178 ms 412 KB Output is correct
7 Correct 143 ms 420 KB Output is correct
8 Correct 102 ms 340 KB Output is correct
9 Correct 194 ms 440 KB Output is correct
10 Correct 56 ms 340 KB Output is correct
11 Correct 53 ms 340 KB Output is correct
12 Correct 59 ms 440 KB Output is correct
13 Correct 101 ms 420 KB Output is correct
14 Correct 102 ms 424 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Incorrect 244 ms 13404 KB Output isn't correct
18 Halted 0 ms 0 KB -