Submission #848354

# Submission time Handle Problem Language Result Execution time Memory
848354 2023-09-12T08:21:12 Z Alora Stranded Far From Home (BOI22_island) C++17
100 / 100
195 ms 42500 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 int long long
#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], xd[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;
        g[u].pb(v); g[v].pb(u);
    }
    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]) if(xd[v]){
            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;
        }
        xd[u] = 1;
    }
    dfs(a[n].se, 1);
    fi(i, 1, n) cout << ans[i];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14940 KB Output is correct
2 Correct 2 ms 14936 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 3 ms 14936 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 15192 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14996 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 15196 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 114 ms 32852 KB Output is correct
4 Correct 122 ms 40544 KB Output is correct
5 Correct 115 ms 34916 KB Output is correct
6 Correct 115 ms 35156 KB Output is correct
7 Correct 128 ms 35156 KB Output is correct
8 Correct 118 ms 42496 KB Output is correct
9 Correct 126 ms 34812 KB Output is correct
10 Correct 79 ms 33728 KB Output is correct
11 Correct 106 ms 41916 KB Output is correct
12 Correct 126 ms 35828 KB Output is correct
13 Correct 112 ms 40276 KB Output is correct
14 Correct 102 ms 39504 KB Output is correct
15 Correct 103 ms 41604 KB Output is correct
16 Correct 75 ms 40692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14936 KB Output is correct
2 Correct 147 ms 30020 KB Output is correct
3 Correct 153 ms 34140 KB Output is correct
4 Correct 116 ms 41604 KB Output is correct
5 Correct 95 ms 38388 KB Output is correct
6 Correct 173 ms 34136 KB Output is correct
7 Correct 112 ms 41456 KB Output is correct
8 Correct 113 ms 41392 KB Output is correct
9 Correct 75 ms 40636 KB Output is correct
10 Correct 124 ms 35152 KB Output is correct
11 Correct 118 ms 33816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14936 KB Output is correct
2 Correct 155 ms 30944 KB Output is correct
3 Correct 195 ms 35084 KB Output is correct
4 Correct 149 ms 35156 KB Output is correct
5 Correct 137 ms 35216 KB Output is correct
6 Correct 123 ms 35312 KB Output is correct
7 Correct 92 ms 38588 KB Output is correct
8 Correct 78 ms 41848 KB Output is correct
9 Correct 81 ms 28752 KB Output is correct
10 Correct 111 ms 33624 KB Output is correct
11 Correct 134 ms 33676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14940 KB Output is correct
2 Correct 2 ms 14936 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 3 ms 14936 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 15192 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14996 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 15196 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 3 ms 14940 KB Output is correct
17 Correct 114 ms 32852 KB Output is correct
18 Correct 122 ms 40544 KB Output is correct
19 Correct 115 ms 34916 KB Output is correct
20 Correct 115 ms 35156 KB Output is correct
21 Correct 128 ms 35156 KB Output is correct
22 Correct 118 ms 42496 KB Output is correct
23 Correct 126 ms 34812 KB Output is correct
24 Correct 79 ms 33728 KB Output is correct
25 Correct 106 ms 41916 KB Output is correct
26 Correct 126 ms 35828 KB Output is correct
27 Correct 112 ms 40276 KB Output is correct
28 Correct 102 ms 39504 KB Output is correct
29 Correct 103 ms 41604 KB Output is correct
30 Correct 75 ms 40692 KB Output is correct
31 Correct 2 ms 14936 KB Output is correct
32 Correct 147 ms 30020 KB Output is correct
33 Correct 153 ms 34140 KB Output is correct
34 Correct 116 ms 41604 KB Output is correct
35 Correct 95 ms 38388 KB Output is correct
36 Correct 173 ms 34136 KB Output is correct
37 Correct 112 ms 41456 KB Output is correct
38 Correct 113 ms 41392 KB Output is correct
39 Correct 75 ms 40636 KB Output is correct
40 Correct 124 ms 35152 KB Output is correct
41 Correct 118 ms 33816 KB Output is correct
42 Correct 2 ms 14936 KB Output is correct
43 Correct 155 ms 30944 KB Output is correct
44 Correct 195 ms 35084 KB Output is correct
45 Correct 149 ms 35156 KB Output is correct
46 Correct 137 ms 35216 KB Output is correct
47 Correct 123 ms 35312 KB Output is correct
48 Correct 92 ms 38588 KB Output is correct
49 Correct 78 ms 41848 KB Output is correct
50 Correct 81 ms 28752 KB Output is correct
51 Correct 111 ms 33624 KB Output is correct
52 Correct 134 ms 33676 KB Output is correct
53 Correct 3 ms 14936 KB Output is correct
54 Correct 3 ms 14940 KB Output is correct
55 Correct 3 ms 14940 KB Output is correct
56 Correct 3 ms 14936 KB Output is correct
57 Correct 4 ms 14940 KB Output is correct
58 Correct 3 ms 14940 KB Output is correct
59 Correct 4 ms 14940 KB Output is correct
60 Correct 3 ms 14940 KB Output is correct
61 Correct 4 ms 15196 KB Output is correct
62 Correct 4 ms 14940 KB Output is correct
63 Correct 5 ms 14940 KB Output is correct
64 Correct 3 ms 14936 KB Output is correct
65 Correct 4 ms 15196 KB Output is correct
66 Correct 3 ms 14940 KB Output is correct
67 Correct 107 ms 37388 KB Output is correct
68 Correct 99 ms 40528 KB Output is correct
69 Correct 122 ms 34644 KB Output is correct
70 Correct 129 ms 35236 KB Output is correct
71 Correct 116 ms 35188 KB Output is correct
72 Correct 121 ms 42500 KB Output is correct
73 Correct 106 ms 34712 KB Output is correct
74 Correct 82 ms 33756 KB Output is correct
75 Correct 103 ms 41920 KB Output is correct
76 Correct 117 ms 35704 KB Output is correct
77 Correct 99 ms 40076 KB Output is correct
78 Correct 100 ms 39772 KB Output is correct
79 Correct 93 ms 41576 KB Output is correct
80 Correct 74 ms 40492 KB Output is correct
81 Correct 151 ms 34132 KB Output is correct
82 Correct 138 ms 34224 KB Output is correct
83 Correct 121 ms 41556 KB Output is correct
84 Correct 90 ms 38188 KB Output is correct
85 Correct 138 ms 34128 KB Output is correct
86 Correct 119 ms 41556 KB Output is correct
87 Correct 113 ms 41468 KB Output is correct
88 Correct 94 ms 34960 KB Output is correct
89 Correct 111 ms 33836 KB Output is correct
90 Correct 146 ms 35492 KB Output is correct
91 Correct 138 ms 35068 KB Output is correct
92 Correct 144 ms 35196 KB Output is correct
93 Correct 136 ms 35368 KB Output is correct
94 Correct 112 ms 35160 KB Output is correct
95 Correct 86 ms 38452 KB Output is correct
96 Correct 75 ms 41812 KB Output is correct
97 Correct 88 ms 28752 KB Output is correct
98 Correct 109 ms 33664 KB Output is correct
99 Correct 106 ms 33616 KB Output is correct
100 Correct 34 ms 21468 KB Output is correct
101 Correct 146 ms 35156 KB Output is correct
102 Correct 133 ms 34556 KB Output is correct
103 Correct 132 ms 34876 KB Output is correct
104 Correct 142 ms 35512 KB Output is correct