Submission #694976

# Submission time Handle Problem Language Result Execution time Memory
694976 2023-02-04T16:10:56 Z finn__ Stranded Far From Home (BOI22_island) C++17
10 / 100
238 ms 17624 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] : 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 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 146 ms 424 KB Output is correct
5 Correct 137 ms 444 KB Output is correct
6 Correct 184 ms 460 KB Output is correct
7 Correct 149 ms 444 KB Output is correct
8 Correct 105 ms 404 KB Output is correct
9 Correct 193 ms 444 KB Output is correct
10 Correct 57 ms 456 KB Output is correct
11 Correct 54 ms 340 KB Output is correct
12 Correct 64 ms 340 KB Output is correct
13 Correct 100 ms 424 KB Output is correct
14 Correct 85 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 224 ms 17544 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 229 ms 17472 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 Incorrect 238 ms 17624 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 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 146 ms 424 KB Output is correct
5 Correct 137 ms 444 KB Output is correct
6 Correct 184 ms 460 KB Output is correct
7 Correct 149 ms 444 KB Output is correct
8 Correct 105 ms 404 KB Output is correct
9 Correct 193 ms 444 KB Output is correct
10 Correct 57 ms 456 KB Output is correct
11 Correct 54 ms 340 KB Output is correct
12 Correct 64 ms 340 KB Output is correct
13 Correct 100 ms 424 KB Output is correct
14 Correct 85 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Incorrect 224 ms 17544 KB Output isn't correct
18 Halted 0 ms 0 KB -