Submission #877841

# Submission time Handle Problem Language Result Execution time Memory
877841 2023-11-23T17:38:35 Z deadeye0 Stranded Far From Home (BOI22_island) C++17
0 / 100
197 ms 46212 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
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);
    }
}

signed 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)] >= val[par(j)]) {
                merge(i, j);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << (bad[i] ? 0 : 1);
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 4 ms 16988 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Incorrect 4 ms 16988 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Incorrect 106 ms 35776 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Incorrect 179 ms 46212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Incorrect 197 ms 39204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 4 ms 16988 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Incorrect 4 ms 16988 KB Output isn't correct
5 Halted 0 ms 0 KB -