Submission #993771

# Submission time Handle Problem Language Result Execution time Memory
993771 2024-06-06T12:04:50 Z amine_aroua Stranded Far From Home (BOI22_island) C++17
100 / 100
260 ms 51384 KB
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
#define int long long
#define pb push_back
#define fore(i , n) for(int i = 0 ; i<n;i++)
#define forr(i , x , y) for(int i = x ; i <= y; i++)
#define forn(i , x , y) for(int i = x ; i >= y; i--)
const int N = 2e5 + 10;
vector<int> adj[N];
int a[N];
int n , m;
vector<int> ans(N , 0);
vector<bool> vis(N , 0);
int sz[N];
vector<int> nadj[N];
struct DSU
{
    vector<int> e;
    vector<int> sm;
    DSU(int _n)
    {
        e.assign(_n , -1);
        sm.assign(_n , 0);
        fore(i , _n)
            sm[i] = a[i];
    }
    int get(int x)
    {
        return (e[x] < 0 ? x : e[x] = get(e[x]));
    }
    int sum(int x)
    {
        return sm[get(x)];
    }
    void unite(int u , int v)
    {
        u = get(u) , v = get(v);
        if(u == v)
            return ;
        sm[u]+=sm[v];
        e[u]+=e[v];
        e[v] = u;
    }
};
void dfsCompute(int x)
{
    for(auto u : nadj[x])
    {
        if(vis[u])
            continue;
        if(sz[u] >= a[x])
        {
            ans[u] = 1;
            dfsCompute(u);
        }
    }
}
signed main()
{
    cin>>n>>m;
    vector<pair<int ,int>> order;
    fore(i , n)
    {
        cin>>a[i];
        order.pb({a[i] , i});
    }
    fore(i , m)
    {
        int u , v;
        cin>>u>>v;
        u-- , v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    sort(order.begin() , order.end());
    DSU dsu(n);
    vector<bool> mark(n , 0);
    fore(j , n)
    {
        int i = order[j].second;
        mark[i] = 1;
        for(auto u : adj[i])
        {
            u = dsu.get(u);
            if(!mark[u] || u == i)
                continue;
            if(sz[u] >= a[i]) {
                nadj[i].pb(u);
            }
            dsu.unite(i , u);
        }
        sz[i] = dsu.sum(i);
    }
    ans[order.back().second] = 1;
    dfsCompute(order.back().second);
    fore(i , n)
        cout<<ans[i];
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11352 KB Output is correct
2 Correct 5 ms 11352 KB Output is correct
3 Correct 6 ms 11356 KB Output is correct
4 Correct 6 ms 11612 KB Output is correct
5 Correct 6 ms 11612 KB Output is correct
6 Correct 6 ms 11612 KB Output is correct
7 Correct 6 ms 11540 KB Output is correct
8 Correct 6 ms 11612 KB Output is correct
9 Correct 6 ms 11612 KB Output is correct
10 Correct 6 ms 11612 KB Output is correct
11 Correct 7 ms 11612 KB Output is correct
12 Correct 7 ms 11512 KB Output is correct
13 Correct 10 ms 11600 KB Output is correct
14 Correct 8 ms 11612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11352 KB Output is correct
2 Correct 4 ms 11356 KB Output is correct
3 Correct 185 ms 40888 KB Output is correct
4 Correct 153 ms 38600 KB Output is correct
5 Correct 212 ms 34496 KB Output is correct
6 Correct 195 ms 35256 KB Output is correct
7 Correct 185 ms 35196 KB Output is correct
8 Correct 214 ms 51260 KB Output is correct
9 Correct 177 ms 34488 KB Output is correct
10 Correct 152 ms 32332 KB Output is correct
11 Correct 179 ms 50868 KB Output is correct
12 Correct 172 ms 38072 KB Output is correct
13 Correct 148 ms 39356 KB Output is correct
14 Correct 161 ms 39464 KB Output is correct
15 Correct 182 ms 50272 KB Output is correct
16 Correct 154 ms 49384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11352 KB Output is correct
2 Correct 207 ms 33908 KB Output is correct
3 Correct 206 ms 34180 KB Output is correct
4 Correct 193 ms 50364 KB Output is correct
5 Correct 164 ms 37300 KB Output is correct
6 Correct 203 ms 33980 KB Output is correct
7 Correct 201 ms 50344 KB Output is correct
8 Correct 213 ms 50484 KB Output is correct
9 Correct 147 ms 49320 KB Output is correct
10 Correct 190 ms 40632 KB Output is correct
11 Correct 188 ms 33992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11352 KB Output is correct
2 Correct 248 ms 36280 KB Output is correct
3 Correct 260 ms 35644 KB Output is correct
4 Correct 221 ms 35768 KB Output is correct
5 Correct 233 ms 37048 KB Output is correct
6 Correct 229 ms 37604 KB Output is correct
7 Correct 185 ms 44268 KB Output is correct
8 Correct 147 ms 44672 KB Output is correct
9 Correct 135 ms 27028 KB Output is correct
10 Correct 157 ms 35164 KB Output is correct
11 Correct 161 ms 33980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11352 KB Output is correct
2 Correct 5 ms 11352 KB Output is correct
3 Correct 6 ms 11356 KB Output is correct
4 Correct 6 ms 11612 KB Output is correct
5 Correct 6 ms 11612 KB Output is correct
6 Correct 6 ms 11612 KB Output is correct
7 Correct 6 ms 11540 KB Output is correct
8 Correct 6 ms 11612 KB Output is correct
9 Correct 6 ms 11612 KB Output is correct
10 Correct 6 ms 11612 KB Output is correct
11 Correct 7 ms 11612 KB Output is correct
12 Correct 7 ms 11512 KB Output is correct
13 Correct 10 ms 11600 KB Output is correct
14 Correct 8 ms 11612 KB Output is correct
15 Correct 4 ms 11352 KB Output is correct
16 Correct 4 ms 11356 KB Output is correct
17 Correct 185 ms 40888 KB Output is correct
18 Correct 153 ms 38600 KB Output is correct
19 Correct 212 ms 34496 KB Output is correct
20 Correct 195 ms 35256 KB Output is correct
21 Correct 185 ms 35196 KB Output is correct
22 Correct 214 ms 51260 KB Output is correct
23 Correct 177 ms 34488 KB Output is correct
24 Correct 152 ms 32332 KB Output is correct
25 Correct 179 ms 50868 KB Output is correct
26 Correct 172 ms 38072 KB Output is correct
27 Correct 148 ms 39356 KB Output is correct
28 Correct 161 ms 39464 KB Output is correct
29 Correct 182 ms 50272 KB Output is correct
30 Correct 154 ms 49384 KB Output is correct
31 Correct 5 ms 11352 KB Output is correct
32 Correct 207 ms 33908 KB Output is correct
33 Correct 206 ms 34180 KB Output is correct
34 Correct 193 ms 50364 KB Output is correct
35 Correct 164 ms 37300 KB Output is correct
36 Correct 203 ms 33980 KB Output is correct
37 Correct 201 ms 50344 KB Output is correct
38 Correct 213 ms 50484 KB Output is correct
39 Correct 147 ms 49320 KB Output is correct
40 Correct 190 ms 40632 KB Output is correct
41 Correct 188 ms 33992 KB Output is correct
42 Correct 6 ms 11352 KB Output is correct
43 Correct 248 ms 36280 KB Output is correct
44 Correct 260 ms 35644 KB Output is correct
45 Correct 221 ms 35768 KB Output is correct
46 Correct 233 ms 37048 KB Output is correct
47 Correct 229 ms 37604 KB Output is correct
48 Correct 185 ms 44268 KB Output is correct
49 Correct 147 ms 44672 KB Output is correct
50 Correct 135 ms 27028 KB Output is correct
51 Correct 157 ms 35164 KB Output is correct
52 Correct 161 ms 33980 KB Output is correct
53 Correct 4 ms 11352 KB Output is correct
54 Correct 5 ms 11292 KB Output is correct
55 Correct 4 ms 11356 KB Output is correct
56 Correct 6 ms 11676 KB Output is correct
57 Correct 7 ms 11612 KB Output is correct
58 Correct 7 ms 11612 KB Output is correct
59 Correct 6 ms 11608 KB Output is correct
60 Correct 6 ms 11612 KB Output is correct
61 Correct 6 ms 11612 KB Output is correct
62 Correct 7 ms 11612 KB Output is correct
63 Correct 7 ms 11612 KB Output is correct
64 Correct 6 ms 11612 KB Output is correct
65 Correct 6 ms 11612 KB Output is correct
66 Correct 6 ms 11664 KB Output is correct
67 Correct 188 ms 40896 KB Output is correct
68 Correct 154 ms 38588 KB Output is correct
69 Correct 198 ms 34640 KB Output is correct
70 Correct 212 ms 35264 KB Output is correct
71 Correct 187 ms 35380 KB Output is correct
72 Correct 218 ms 51384 KB Output is correct
73 Correct 179 ms 34492 KB Output is correct
74 Correct 145 ms 32440 KB Output is correct
75 Correct 219 ms 50872 KB Output is correct
76 Correct 162 ms 38136 KB Output is correct
77 Correct 145 ms 39608 KB Output is correct
78 Correct 161 ms 39436 KB Output is correct
79 Correct 216 ms 50536 KB Output is correct
80 Correct 150 ms 49340 KB Output is correct
81 Correct 188 ms 33976 KB Output is correct
82 Correct 216 ms 34496 KB Output is correct
83 Correct 200 ms 50364 KB Output is correct
84 Correct 153 ms 37304 KB Output is correct
85 Correct 218 ms 34012 KB Output is correct
86 Correct 199 ms 50368 KB Output is correct
87 Correct 204 ms 50372 KB Output is correct
88 Correct 179 ms 40460 KB Output is correct
89 Correct 154 ms 34124 KB Output is correct
90 Correct 218 ms 36028 KB Output is correct
91 Correct 224 ms 35512 KB Output is correct
92 Correct 221 ms 35776 KB Output is correct
93 Correct 231 ms 37004 KB Output is correct
94 Correct 194 ms 37528 KB Output is correct
95 Correct 175 ms 44220 KB Output is correct
96 Correct 136 ms 44580 KB Output is correct
97 Correct 127 ms 26972 KB Output is correct
98 Correct 171 ms 35324 KB Output is correct
99 Correct 160 ms 33980 KB Output is correct
100 Correct 71 ms 18152 KB Output is correct
101 Correct 257 ms 35344 KB Output is correct
102 Correct 191 ms 36280 KB Output is correct
103 Correct 199 ms 35804 KB Output is correct
104 Correct 216 ms 36312 KB Output is correct