Submission #573289

# Submission time Handle Problem Language Result Execution time Memory
573289 2022-06-06T11:15:51 Z AmirElarbi Stranded Far From Home (BOI22_island) C++14
100 / 100
224 ms 42716 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9+7
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 4e5+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
vii s;
vi adj[nax], nds[nax];
ll ans[nax];
ll p[nax], sz[nax];
bool vis[nax];
int find_set(int v) {
    if (v == p[v])
        return v;
    return p[v] = find_set(p[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b){
        if(nds[b].size() > nds[a].size()) swap(nds[a],nds[b]);
        for(auto x : nds[b]) nds[a].pb(x);
        p[b] = a;
        sz[a] += sz[b];
    }
}
int main(){
    optimise;
    int n,m;
    cin >>n >> m;
    for (int i = 0; i < n; ++i)
    {
        int val;
        cin >> val;
        sz[i] = val;
        p[i] = i;
        nds[i].pb(i);
        s.pb({val,i});
    }
    for (int i = 0; i < m; ++i)
    {
        int a,b;
        cin >> a >> b;
        a--,b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n; ++i)
    {
        int u = find_set(s[i].se);
        for(auto x : adj[u]){
            if(!vis[x]) continue;
            x = find_set(x);
            if(sz[u] > sz[x]) nds[x].clear();
        }
        for(auto x : adj[u]) if(vis[x]) union_sets(x,u);
        vis[u] = 1;  
    }
    for(auto x: nds[find_set(0)]) ans[x] = 1;
    for (int i = 0; i < n; ++i)
    {
        cout << ans[i];
    }
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19104 KB Output is correct
2 Correct 11 ms 19044 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 12 ms 19348 KB Output is correct
6 Correct 11 ms 19260 KB Output is correct
7 Correct 13 ms 19284 KB Output is correct
8 Correct 12 ms 19164 KB Output is correct
9 Correct 12 ms 19284 KB Output is correct
10 Correct 12 ms 19284 KB Output is correct
11 Correct 11 ms 19284 KB Output is correct
12 Correct 10 ms 19284 KB Output is correct
13 Correct 11 ms 19284 KB Output is correct
14 Correct 12 ms 19296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19016 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 156 ms 39864 KB Output is correct
4 Correct 140 ms 38584 KB Output is correct
5 Correct 173 ms 40644 KB Output is correct
6 Correct 182 ms 41600 KB Output is correct
7 Correct 177 ms 41416 KB Output is correct
8 Correct 160 ms 40060 KB Output is correct
9 Correct 148 ms 41960 KB Output is correct
10 Correct 150 ms 37560 KB Output is correct
11 Correct 147 ms 40780 KB Output is correct
12 Correct 169 ms 38052 KB Output is correct
13 Correct 136 ms 38500 KB Output is correct
14 Correct 148 ms 38696 KB Output is correct
15 Correct 144 ms 40004 KB Output is correct
16 Correct 117 ms 39832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 206 ms 42284 KB Output is correct
3 Correct 216 ms 42388 KB Output is correct
4 Correct 162 ms 39992 KB Output is correct
5 Correct 148 ms 38244 KB Output is correct
6 Correct 219 ms 42380 KB Output is correct
7 Correct 169 ms 40048 KB Output is correct
8 Correct 167 ms 40044 KB Output is correct
9 Correct 105 ms 39884 KB Output is correct
10 Correct 146 ms 39736 KB Output is correct
11 Correct 170 ms 38444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19136 KB Output is correct
2 Correct 215 ms 40212 KB Output is correct
3 Correct 216 ms 40400 KB Output is correct
4 Correct 222 ms 41628 KB Output is correct
5 Correct 210 ms 42716 KB Output is correct
6 Correct 178 ms 40120 KB Output is correct
7 Correct 146 ms 41880 KB Output is correct
8 Correct 104 ms 38712 KB Output is correct
9 Correct 130 ms 30376 KB Output is correct
10 Correct 194 ms 42192 KB Output is correct
11 Correct 166 ms 38508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19104 KB Output is correct
2 Correct 11 ms 19044 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 12 ms 19348 KB Output is correct
6 Correct 11 ms 19260 KB Output is correct
7 Correct 13 ms 19284 KB Output is correct
8 Correct 12 ms 19164 KB Output is correct
9 Correct 12 ms 19284 KB Output is correct
10 Correct 12 ms 19284 KB Output is correct
11 Correct 11 ms 19284 KB Output is correct
12 Correct 10 ms 19284 KB Output is correct
13 Correct 11 ms 19284 KB Output is correct
14 Correct 12 ms 19296 KB Output is correct
15 Correct 10 ms 19016 KB Output is correct
16 Correct 10 ms 19028 KB Output is correct
17 Correct 156 ms 39864 KB Output is correct
18 Correct 140 ms 38584 KB Output is correct
19 Correct 173 ms 40644 KB Output is correct
20 Correct 182 ms 41600 KB Output is correct
21 Correct 177 ms 41416 KB Output is correct
22 Correct 160 ms 40060 KB Output is correct
23 Correct 148 ms 41960 KB Output is correct
24 Correct 150 ms 37560 KB Output is correct
25 Correct 147 ms 40780 KB Output is correct
26 Correct 169 ms 38052 KB Output is correct
27 Correct 136 ms 38500 KB Output is correct
28 Correct 148 ms 38696 KB Output is correct
29 Correct 144 ms 40004 KB Output is correct
30 Correct 117 ms 39832 KB Output is correct
31 Correct 10 ms 19028 KB Output is correct
32 Correct 206 ms 42284 KB Output is correct
33 Correct 216 ms 42388 KB Output is correct
34 Correct 162 ms 39992 KB Output is correct
35 Correct 148 ms 38244 KB Output is correct
36 Correct 219 ms 42380 KB Output is correct
37 Correct 169 ms 40048 KB Output is correct
38 Correct 167 ms 40044 KB Output is correct
39 Correct 105 ms 39884 KB Output is correct
40 Correct 146 ms 39736 KB Output is correct
41 Correct 170 ms 38444 KB Output is correct
42 Correct 10 ms 19136 KB Output is correct
43 Correct 215 ms 40212 KB Output is correct
44 Correct 216 ms 40400 KB Output is correct
45 Correct 222 ms 41628 KB Output is correct
46 Correct 210 ms 42716 KB Output is correct
47 Correct 178 ms 40120 KB Output is correct
48 Correct 146 ms 41880 KB Output is correct
49 Correct 104 ms 38712 KB Output is correct
50 Correct 130 ms 30376 KB Output is correct
51 Correct 194 ms 42192 KB Output is correct
52 Correct 166 ms 38508 KB Output is correct
53 Correct 11 ms 19028 KB Output is correct
54 Correct 10 ms 19036 KB Output is correct
55 Correct 10 ms 19076 KB Output is correct
56 Correct 12 ms 19284 KB Output is correct
57 Correct 11 ms 19284 KB Output is correct
58 Correct 11 ms 19284 KB Output is correct
59 Correct 13 ms 19284 KB Output is correct
60 Correct 11 ms 19156 KB Output is correct
61 Correct 11 ms 19284 KB Output is correct
62 Correct 12 ms 19284 KB Output is correct
63 Correct 11 ms 19352 KB Output is correct
64 Correct 11 ms 19324 KB Output is correct
65 Correct 12 ms 19288 KB Output is correct
66 Correct 12 ms 19284 KB Output is correct
67 Correct 152 ms 39780 KB Output is correct
68 Correct 147 ms 38616 KB Output is correct
69 Correct 186 ms 40716 KB Output is correct
70 Correct 173 ms 41384 KB Output is correct
71 Correct 175 ms 41488 KB Output is correct
72 Correct 155 ms 40140 KB Output is correct
73 Correct 149 ms 41984 KB Output is correct
74 Correct 135 ms 37436 KB Output is correct
75 Correct 145 ms 40820 KB Output is correct
76 Correct 168 ms 38052 KB Output is correct
77 Correct 139 ms 38452 KB Output is correct
78 Correct 147 ms 38576 KB Output is correct
79 Correct 143 ms 40048 KB Output is correct
80 Correct 103 ms 39864 KB Output is correct
81 Correct 198 ms 42272 KB Output is correct
82 Correct 205 ms 42372 KB Output is correct
83 Correct 161 ms 40052 KB Output is correct
84 Correct 162 ms 38396 KB Output is correct
85 Correct 199 ms 42240 KB Output is correct
86 Correct 155 ms 40120 KB Output is correct
87 Correct 159 ms 40088 KB Output is correct
88 Correct 145 ms 39824 KB Output is correct
89 Correct 162 ms 38436 KB Output is correct
90 Correct 206 ms 40092 KB Output is correct
91 Correct 224 ms 40504 KB Output is correct
92 Correct 220 ms 41600 KB Output is correct
93 Correct 201 ms 42680 KB Output is correct
94 Correct 208 ms 40272 KB Output is correct
95 Correct 138 ms 41912 KB Output is correct
96 Correct 106 ms 38776 KB Output is correct
97 Correct 117 ms 30432 KB Output is correct
98 Correct 188 ms 42168 KB Output is correct
99 Correct 165 ms 38444 KB Output is correct
100 Correct 46 ms 21588 KB Output is correct
101 Correct 213 ms 40760 KB Output is correct
102 Correct 184 ms 36364 KB Output is correct
103 Correct 178 ms 36268 KB Output is correct
104 Correct 210 ms 39424 KB Output is correct