Submission #710725

# Submission time Handle Problem Language Result Execution time Memory
710725 2023-03-15T17:11:59 Z sysia Stranded Far From Home (BOI22_island) C++17
0 / 100
409 ms 46612 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;

struct DSU{
    vector<int>rep, sz;

    DSU(int n, vector<int>&a){
        rep.assign(n+1, 0);
        iota(rep.begin(), rep.end(), 0);
        sz = a;
    }

    int f(int a){return a == rep[a] ? a : rep[a] = f(rep[a]);}

    bool u(int a, int b){
        a = f(a);b = f(b);
        if (a == b) return 0;
        if (sz[a] < sz[b]) swap(a, b);
        sz[a] += sz[b];
        rep[b] = a;
        return 1;
    }
};

void solve(){
    int n, m; cin >> n >> m;
    vector<int>a(n+1);
    map<int, vector<int>>event;
    for (int i = 1; i<=n; i++) {
        cin >> a[i];
        event[a[i]].emplace_back(i);
    }
    vector<T>edges;
    vector<vector<int>>g(n+1);
    for (int i = 0; i<m; i++) {
        int a, b; cin >> a >> b;
        edges.emplace_back(a, b);
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    sort(edges.begin(), edges.end(), [&](auto x, auto y){
        return max(a[x.first], a[x.second]) < max(a[y.first], a[y.second]);
    });
    DSU dsu(n+2, a);
    int ptr = -1;
    vector<bool>ans(n+1, 1);
    for (auto [w, curr]: event){
        while (ptr+1 < (int)edges.size() && max(a[edges[ptr+1].first], a[edges[ptr+1].second]) <= w) {
            ptr++;
            debug(edges[ptr]);
            dsu.u(edges[ptr].first, edges[ptr].second);
        }
        for (auto v: curr){
            for (auto x: g[v]){
                debug(v, x, dsu.sz[dsu.f(v)], dsu.sz[dsu.f(x)]);
                if (a[x] > a[v] && dsu.sz[dsu.f(v)] < dsu.sz[dsu.f(x)]){
                    ans[v] = 0;
                }
            }
            
        }
    }
    for (int i = 1; i<=n; i++) cout << (ans[i] ? 1 : 0);
    cout << "\n";
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}
# 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 212 KB Output is correct
4 Incorrect 2 ms 724 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 248 ms 46612 KB Output is correct
4 Incorrect 164 ms 26360 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Incorrect 409 ms 45436 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 245 ms 26608 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 212 KB Output is correct
4 Incorrect 2 ms 724 KB Output isn't correct
5 Halted 0 ms 0 KB -