Submission #653895

# Submission time Handle Problem Language Result Execution time Memory
653895 2022-10-28T18:45:34 Z urosk Stranded Far From Home (BOI22_island) C++14
100 / 100
268 ms 38440 KB
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}

#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 200005
ll n,m;
pll a[maxn];
vector<ll> g[maxn];
vector<ll> g2[maxn];
ll dsu[maxn],sum[maxn],sizi[maxn];
bool ok[maxn];
bool vis[maxn];
void dfs(ll u){
    if(!ok[u]) return;
    ok[u] = 0;
    for(ll s : g2[u]) dfs(s);
}
ll root(ll x){
    while(x!=dsu[x]){dsu[x] = dsu[dsu[x]];x = dsu[x];}
    return x;
}
void upd(ll x,ll y){
    x = root(x); y = root(y);
    if(x==y) return;
    dsu[x] = y;
    g2[y].pb(x);
    sizi[y]+=sizi[x];
    sum[y]+=sum[x];
}
void tc(){
    cin >> n >> m;
    for(ll i = 1;i<=n;i++) cin >> a[i].fi;
    for(ll i = 1;i<=n;i++) a[i].sc = i;
    for(ll i = 1;i<=n;i++) sum[i] = a[i].fi;
    for(ll i = 1;i<=m;i++){
        ll x,y; cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    iota(dsu+1,dsu+1+n,1);
    fill(ok+1,ok+1+n,1);
    fill(sizi+1,sizi+1+n,1);
    sort(a+1,a+1+n);
    for(ll j = 1;j<=n;j++){
        ll i = a[j].sc;
        ll x = a[j].fi;
        vis[i] = 1;
        for(ll j : g[i]){
            if(!vis[j]) continue;
            j = root(j);
            if(sum[j]<x){
                dfs(j);
            }
        }
        for(ll j : g[i]){
            if(!vis[j]) continue;
            upd(j,i);
        }
    }
    for(ll i = 1;i<=n;i++){
        cout<<(ok[i]&&(sizi[root(i)]==n));
    }
    cout<<endl;
}
int main(){
	daj_mi_malo_vremena
    int t; t = 1;
    while(t--){
        tc();
    }
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 6 ms 9724 KB Output is correct
4 Correct 7 ms 9952 KB Output is correct
5 Correct 6 ms 9940 KB Output is correct
6 Correct 7 ms 9864 KB Output is correct
7 Correct 7 ms 9936 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9940 KB Output is correct
10 Correct 9 ms 9864 KB Output is correct
11 Correct 7 ms 9900 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 7 ms 9948 KB Output is correct
14 Correct 7 ms 9956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 166 ms 29940 KB Output is correct
4 Correct 189 ms 38416 KB Output is correct
5 Correct 181 ms 33112 KB Output is correct
6 Correct 202 ms 33808 KB Output is correct
7 Correct 213 ms 33924 KB Output is correct
8 Correct 193 ms 35980 KB Output is correct
9 Correct 184 ms 33564 KB Output is correct
10 Correct 114 ms 32340 KB Output is correct
11 Correct 145 ms 35624 KB Output is correct
12 Correct 183 ms 34020 KB Output is correct
13 Correct 183 ms 37984 KB Output is correct
14 Correct 145 ms 37664 KB Output is correct
15 Correct 136 ms 35008 KB Output is correct
16 Correct 97 ms 34132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 192 ms 28652 KB Output is correct
3 Correct 202 ms 32960 KB Output is correct
4 Correct 154 ms 35020 KB Output is correct
5 Correct 140 ms 36480 KB Output is correct
6 Correct 197 ms 32920 KB Output is correct
7 Correct 173 ms 35020 KB Output is correct
8 Correct 171 ms 35072 KB Output is correct
9 Correct 94 ms 34120 KB Output is correct
10 Correct 157 ms 31216 KB Output is correct
11 Correct 192 ms 32272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 235 ms 29664 KB Output is correct
3 Correct 245 ms 33744 KB Output is correct
4 Correct 243 ms 34004 KB Output is correct
5 Correct 198 ms 33916 KB Output is correct
6 Correct 164 ms 33012 KB Output is correct
7 Correct 120 ms 34392 KB Output is correct
8 Correct 98 ms 37624 KB Output is correct
9 Correct 173 ms 24824 KB Output is correct
10 Correct 174 ms 32504 KB Output is correct
11 Correct 173 ms 32336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 6 ms 9724 KB Output is correct
4 Correct 7 ms 9952 KB Output is correct
5 Correct 6 ms 9940 KB Output is correct
6 Correct 7 ms 9864 KB Output is correct
7 Correct 7 ms 9936 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9940 KB Output is correct
10 Correct 9 ms 9864 KB Output is correct
11 Correct 7 ms 9900 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 7 ms 9948 KB Output is correct
14 Correct 7 ms 9956 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 166 ms 29940 KB Output is correct
18 Correct 189 ms 38416 KB Output is correct
19 Correct 181 ms 33112 KB Output is correct
20 Correct 202 ms 33808 KB Output is correct
21 Correct 213 ms 33924 KB Output is correct
22 Correct 193 ms 35980 KB Output is correct
23 Correct 184 ms 33564 KB Output is correct
24 Correct 114 ms 32340 KB Output is correct
25 Correct 145 ms 35624 KB Output is correct
26 Correct 183 ms 34020 KB Output is correct
27 Correct 183 ms 37984 KB Output is correct
28 Correct 145 ms 37664 KB Output is correct
29 Correct 136 ms 35008 KB Output is correct
30 Correct 97 ms 34132 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 192 ms 28652 KB Output is correct
33 Correct 202 ms 32960 KB Output is correct
34 Correct 154 ms 35020 KB Output is correct
35 Correct 140 ms 36480 KB Output is correct
36 Correct 197 ms 32920 KB Output is correct
37 Correct 173 ms 35020 KB Output is correct
38 Correct 171 ms 35072 KB Output is correct
39 Correct 94 ms 34120 KB Output is correct
40 Correct 157 ms 31216 KB Output is correct
41 Correct 192 ms 32272 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 235 ms 29664 KB Output is correct
44 Correct 245 ms 33744 KB Output is correct
45 Correct 243 ms 34004 KB Output is correct
46 Correct 198 ms 33916 KB Output is correct
47 Correct 164 ms 33012 KB Output is correct
48 Correct 120 ms 34392 KB Output is correct
49 Correct 98 ms 37624 KB Output is correct
50 Correct 173 ms 24824 KB Output is correct
51 Correct 174 ms 32504 KB Output is correct
52 Correct 173 ms 32336 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 6 ms 9684 KB Output is correct
55 Correct 7 ms 9684 KB Output is correct
56 Correct 7 ms 9872 KB Output is correct
57 Correct 8 ms 10028 KB Output is correct
58 Correct 8 ms 9880 KB Output is correct
59 Correct 7 ms 9868 KB Output is correct
60 Correct 7 ms 9812 KB Output is correct
61 Correct 8 ms 9940 KB Output is correct
62 Correct 7 ms 9940 KB Output is correct
63 Correct 7 ms 9868 KB Output is correct
64 Correct 6 ms 9940 KB Output is correct
65 Correct 6 ms 9996 KB Output is correct
66 Correct 7 ms 9940 KB Output is correct
67 Correct 152 ms 34140 KB Output is correct
68 Correct 145 ms 38440 KB Output is correct
69 Correct 158 ms 33080 KB Output is correct
70 Correct 207 ms 33868 KB Output is correct
71 Correct 159 ms 33940 KB Output is correct
72 Correct 178 ms 35936 KB Output is correct
73 Correct 191 ms 33496 KB Output is correct
74 Correct 112 ms 32368 KB Output is correct
75 Correct 144 ms 35632 KB Output is correct
76 Correct 252 ms 33976 KB Output is correct
77 Correct 136 ms 37848 KB Output is correct
78 Correct 148 ms 37668 KB Output is correct
79 Correct 140 ms 35060 KB Output is correct
80 Correct 103 ms 34128 KB Output is correct
81 Correct 183 ms 32860 KB Output is correct
82 Correct 211 ms 32976 KB Output is correct
83 Correct 211 ms 35120 KB Output is correct
84 Correct 129 ms 36520 KB Output is correct
85 Correct 190 ms 32988 KB Output is correct
86 Correct 190 ms 35088 KB Output is correct
87 Correct 172 ms 35036 KB Output is correct
88 Correct 181 ms 31300 KB Output is correct
89 Correct 180 ms 32408 KB Output is correct
90 Correct 196 ms 33868 KB Output is correct
91 Correct 220 ms 33908 KB Output is correct
92 Correct 231 ms 33980 KB Output is correct
93 Correct 199 ms 33960 KB Output is correct
94 Correct 167 ms 32920 KB Output is correct
95 Correct 121 ms 34400 KB Output is correct
96 Correct 106 ms 37636 KB Output is correct
97 Correct 192 ms 24872 KB Output is correct
98 Correct 196 ms 32544 KB Output is correct
99 Correct 183 ms 32384 KB Output is correct
100 Correct 50 ms 16324 KB Output is correct
101 Correct 268 ms 33992 KB Output is correct
102 Correct 180 ms 30096 KB Output is correct
103 Correct 228 ms 31076 KB Output is correct
104 Correct 256 ms 33564 KB Output is correct