Submission #722906

# Submission time Handle Problem Language Result Execution time Memory
722906 2023-04-13T05:23:31 Z kas_s Stranded Far From Home (BOI22_island) C++17
0 / 100
142 ms 12064 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

int N;
vector<vector<int>> adj;
vector<int> cnt;
vector<bool> vis;

int curr = 0;
void dfs(int pos) {
    vis[pos] = true;
    curr += cnt[pos];
    for (auto &v: adj[pos]) {
        if (vis[v] || cnt[v] > curr) continue;
        dfs(v);
    }
}

bool comp(int a, int b) {
    return cnt[a] < cnt[b];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int M;
    cin >> N >> M;
    cnt.resize(N + 1);
    for (int i = 1; i <= N; i++) cin >> cnt[i];
    adj.resize(N + 1);
    for (int i = 0, u, v; i < M; i++) {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= N; i++) {
        sort(adj[i].begin(), adj[i].end(), comp);
    }
    string res;
    if (N <= 2000 && M <= 2000) {
        vis.resize(N + 1);
        for (int i = 1; i <= N; i++) {
            fill(vis.begin(), vis.end(), false);
            curr = 0;
            dfs(i);
            bool ok = true;
            for (int i = 1; i <= N; i++) {
                if (!vis[i]) {
                    ok = false;
                    break;
                }
            }
            res.push_back((ok ? '1' : '0'));
        }
        cout << res;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 2 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 115 ms 12064 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 112 ms 11956 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 142 ms 12032 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 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 2 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -