답안 #625260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625260 2022-08-09T17:40:27 Z Ooops_sorry Stranded Far From Home (BOI22_island) C++14
0 / 100
347 ms 14644 KB
#include<bits/stdc++.h>

using namespace std;

mt19937 rnd(51);

#define ll long long
#define pb push_back
#define ld long double

const int N = 2e5 + 10;
vector<int> g[N];

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> s(n), good(n), bad(n);
    int mx = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        mx = max(mx, s[i]);
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int i, int j){return s[i] > s[j];});
    for (auto i : ord) {
        if (s[i] == mx) {
            good[i] = 1;
            continue;
        }
        ll sum = s[i];
        vector<bool> used(n);
        set<pair<int,int>> st;
        used[i] = 1;
        for (auto to : g[i]) {
             if (!used[to]) {
                used[to] = 1;
                st.insert({s[to], to});
            }
        }
        while (st.size() > 0 && st.begin()->first <= sum) {
            int v = st.begin()->second;
            sum += st.begin()->first;
            if (sum >= mx) {
                break;
            }
            for (auto to : g[v]) {
                if (!used[to]) {
                    used[to] = 1;
                    st.insert({s[to], to});
                }
            }
        }
        if (sum >= mx) {
            good[i] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << good[i];
    }
    cout << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 4 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Incorrect 275 ms 14644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 347 ms 14584 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 283 ms 14560 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 4 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -