Submission #877843

# Submission time Handle Problem Language Result Execution time Memory
877843 2023-11-23T18:12:03 Z deadeye0 Stranded Far From Home (BOI22_island) C++17
0 / 100
190 ms 37188 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define si second
#define ar array
#define pb push_back
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;  
typedef vector<int> vi;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int N = 200010;
int n, m;
int s[N], p[N], vis[N], bad[N];
ll val[N];
vector<int> g[N];
vector<int> st[N];

int par(int x) {return p[x];}
bool same(int x, int y) {return par(x) == par(y);}
void merge(int x, int y) {
    x = par(x), y = par(y);
    if (st[x].size() < st[y].size()) swap(x, y);
    if (x == y) return;
    val[x] += val[y];
    while (st[y].size()) {
        int v = st[y].back();
        st[y].pop_back();
        p[v] = x;
        st[x].pb(v);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(ios::badbit|ios::failbit);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        val[i] = s[i];
        p[i] = i;
        st[i] = vector<int>(1, 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> order(n);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int x, int y) {
        return s[x] < s[y];
    });
    for (auto i: order) {
        vis[i] = 1;
        sort(g[i].begin(), g[i].end(), [&](int x, int y) {
            return s[x] < s[y];
        });
        for (auto j: g[i]) {
            if (same(i, j)) continue;
            if (vis[j]) {
                if (val[par(i)] > val[par(j)]) {
                    for (auto v: st[par(j)]) {
                        bad[v] = 1;
                    }
                }
                merge(i, j);
            } 
            if (val[par(i)] >= s[j]) {
                merge(i, j);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << (bad[i] ? 0 : 1);
    }
    cout << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12888 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 4 ms 12892 KB Output is correct
4 Incorrect 4 ms 12892 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12888 KB Output is correct
3 Correct 113 ms 29212 KB Output is correct
4 Correct 104 ms 34812 KB Output is correct
5 Correct 127 ms 36688 KB Output is correct
6 Incorrect 135 ms 37188 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12888 KB Output is correct
2 Incorrect 167 ms 35392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12892 KB Output is correct
2 Incorrect 190 ms 30892 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12888 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 4 ms 12892 KB Output is correct
4 Incorrect 4 ms 12892 KB Output isn't correct
5 Halted 0 ms 0 KB -