Submission #848351

# Submission time Handle Problem Language Result Execution time Memory
848351 2023-09-12T08:16:20 Z Alora Stranded Far From Home (BOI22_island) C++17
0 / 100
144 ms 29708 KB
#include <bits/stdc++.h>
#define name "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, ll>
#define getbit(i, j) ((i >> j) & 1)
#define pb push_back
#define all(v) v.begin(), v.end()
#define maxn 200005
const int M = 1e9 + 7;
using namespace std;
mt19937_64 rng(time(0));
int n, m, root[maxn], sz[maxn], ans[maxn];
pii a[maxn];
vector <int> g[maxn], f[maxn];

int get(int u){
    if(root[u] == 0) return u;
    return (root[u] = get(root[u]));
}

void dfs(int u, int ok){
    ans[u] &= ok;
    for(auto v: f[u]) dfs(v, ans[u]);
}
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
//	freopen(name".inp","r",stdin);
//	freopen(name".out","w",stdout);
    cin >> n >> m;
    fi(i, 1, n){
        int x; cin >> x;
        a[i] = {x, i};
        sz[i] = x;
    }
    fi(i, 1, m){
        int u, v; cin >> u >> v;
        if(a[u] < a[v]) swap(u, v);
        g[u].pb(v);
    }
    sort(a + 1, a + n + 1);
    fi(i, 1, n) ans[i] = 1;
    fi(i, 1, n){
        auto [w, u] = a[i];
        for(auto v: g[u]){
            int x = get(v);
            if(x == u) continue;
            f[u].pb(x);
            root[x] = u;
            sz[u] += sz[x];
            if(sz[x] < w) ans[x] = 0;
        }
    }
    dfs(a[n].se, 1);
    fi(i, 1, n) cout << ans[i];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Incorrect 3 ms 12892 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 13144 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Incorrect 84 ms 29708 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Incorrect 121 ms 27220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12888 KB Output is correct
2 Incorrect 144 ms 27196 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Incorrect 3 ms 12892 KB Output isn't correct
5 Halted 0 ms 0 KB -