Submission #757837

# Submission time Handle Problem Language Result Execution time Memory
757837 2023-06-13T19:17:24 Z abcvuitunggio Stranded Far From Home (BOI22_island) C++17
100 / 100
432 ms 31676 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct edge{
    int u,v;
}e[200001];
int n,m,p[200001],a[200001],cnt[200001];
set <int> s[200001];
string res;
int f(int i){
    return (p[i]==i?i:p[i]=f(p[i]));
}
void unite(int u, int v){
    int w=max(cnt[u],cnt[v]);
    u=f(u);
    v=f(v);
    if (u==v)
        return;
    if (a[u]<w)
        s[u].clear();
    if (a[v]<w)
        s[v].clear();
    if (s[u].size()<s[v].size())
        swap(u,v);
    a[u]+=a[v];
    p[v]=u;
    for (int i:s[v])
        s[u].insert(i);
    s[v].clear();
}
int32_t main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> m;
    for (int i=1;i<=n;i++){
        cin >> a[i];
        cnt[i]=a[i];
        p[i]=i;
        res+='0';
        s[i].insert(i);
    }
    for (int i=0;i<m;i++)
        cin >> e[i].u >> e[i].v;
    sort(e,e+m,[](edge x, edge y){return max(a[x.u],a[x.v])<max(a[y.u],a[y.v]);});
    for (int i=0;i<m;i++)
        unite(e[i].u,e[i].v);
    for (int i:s[f(1)])
        res[i-1]='1';
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9620 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9872 KB Output is correct
6 Correct 6 ms 9864 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9860 KB Output is correct
9 Correct 7 ms 9940 KB Output is correct
10 Correct 9 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 7 ms 9940 KB Output is correct
13 Correct 7 ms 9940 KB Output is correct
14 Correct 7 ms 9840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9736 KB Output is correct
3 Correct 113 ms 27256 KB Output is correct
4 Correct 348 ms 31676 KB Output is correct
5 Correct 241 ms 27724 KB Output is correct
6 Correct 275 ms 28328 KB Output is correct
7 Correct 241 ms 28428 KB Output is correct
8 Correct 432 ms 30832 KB Output is correct
9 Correct 190 ms 28388 KB Output is correct
10 Correct 129 ms 28020 KB Output is correct
11 Correct 288 ms 28024 KB Output is correct
12 Correct 204 ms 28036 KB Output is correct
13 Correct 394 ms 31612 KB Output is correct
14 Correct 324 ms 30924 KB Output is correct
15 Correct 146 ms 28484 KB Output is correct
16 Correct 115 ms 27952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 268 ms 27232 KB Output is correct
3 Correct 288 ms 28572 KB Output is correct
4 Correct 423 ms 31220 KB Output is correct
5 Correct 403 ms 30560 KB Output is correct
6 Correct 252 ms 28568 KB Output is correct
7 Correct 155 ms 28492 KB Output is correct
8 Correct 139 ms 28572 KB Output is correct
9 Correct 131 ms 27852 KB Output is correct
10 Correct 251 ms 28088 KB Output is correct
11 Correct 269 ms 27980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 257 ms 27172 KB Output is correct
3 Correct 297 ms 28372 KB Output is correct
4 Correct 324 ms 28512 KB Output is correct
5 Correct 395 ms 29200 KB Output is correct
6 Correct 337 ms 27856 KB Output is correct
7 Correct 289 ms 28436 KB Output is correct
8 Correct 140 ms 29324 KB Output is correct
9 Correct 143 ms 20760 KB Output is correct
10 Correct 418 ms 29560 KB Output is correct
11 Correct 306 ms 28140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9620 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9872 KB Output is correct
6 Correct 6 ms 9864 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9860 KB Output is correct
9 Correct 7 ms 9940 KB Output is correct
10 Correct 9 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 7 ms 9940 KB Output is correct
13 Correct 7 ms 9940 KB Output is correct
14 Correct 7 ms 9840 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9736 KB Output is correct
17 Correct 113 ms 27256 KB Output is correct
18 Correct 348 ms 31676 KB Output is correct
19 Correct 241 ms 27724 KB Output is correct
20 Correct 275 ms 28328 KB Output is correct
21 Correct 241 ms 28428 KB Output is correct
22 Correct 432 ms 30832 KB Output is correct
23 Correct 190 ms 28388 KB Output is correct
24 Correct 129 ms 28020 KB Output is correct
25 Correct 288 ms 28024 KB Output is correct
26 Correct 204 ms 28036 KB Output is correct
27 Correct 394 ms 31612 KB Output is correct
28 Correct 324 ms 30924 KB Output is correct
29 Correct 146 ms 28484 KB Output is correct
30 Correct 115 ms 27952 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 268 ms 27232 KB Output is correct
33 Correct 288 ms 28572 KB Output is correct
34 Correct 423 ms 31220 KB Output is correct
35 Correct 403 ms 30560 KB Output is correct
36 Correct 252 ms 28568 KB Output is correct
37 Correct 155 ms 28492 KB Output is correct
38 Correct 139 ms 28572 KB Output is correct
39 Correct 131 ms 27852 KB Output is correct
40 Correct 251 ms 28088 KB Output is correct
41 Correct 269 ms 27980 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 257 ms 27172 KB Output is correct
44 Correct 297 ms 28372 KB Output is correct
45 Correct 324 ms 28512 KB Output is correct
46 Correct 395 ms 29200 KB Output is correct
47 Correct 337 ms 27856 KB Output is correct
48 Correct 289 ms 28436 KB Output is correct
49 Correct 140 ms 29324 KB Output is correct
50 Correct 143 ms 20760 KB Output is correct
51 Correct 418 ms 29560 KB Output is correct
52 Correct 306 ms 28140 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 6 ms 9728 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 6 ms 9812 KB Output is correct
57 Correct 7 ms 9940 KB Output is correct
58 Correct 7 ms 9812 KB Output is correct
59 Correct 7 ms 9812 KB Output is correct
60 Correct 6 ms 9812 KB Output is correct
61 Correct 6 ms 9940 KB Output is correct
62 Correct 7 ms 9940 KB Output is correct
63 Correct 6 ms 9940 KB Output is correct
64 Correct 6 ms 9940 KB Output is correct
65 Correct 8 ms 9940 KB Output is correct
66 Correct 6 ms 9940 KB Output is correct
67 Correct 119 ms 28592 KB Output is correct
68 Correct 377 ms 31660 KB Output is correct
69 Correct 231 ms 27768 KB Output is correct
70 Correct 238 ms 28404 KB Output is correct
71 Correct 260 ms 28472 KB Output is correct
72 Correct 416 ms 30868 KB Output is correct
73 Correct 169 ms 28360 KB Output is correct
74 Correct 129 ms 28048 KB Output is correct
75 Correct 256 ms 28040 KB Output is correct
76 Correct 217 ms 28020 KB Output is correct
77 Correct 367 ms 31616 KB Output is correct
78 Correct 350 ms 31032 KB Output is correct
79 Correct 151 ms 28484 KB Output is correct
80 Correct 107 ms 27796 KB Output is correct
81 Correct 254 ms 28392 KB Output is correct
82 Correct 266 ms 28520 KB Output is correct
83 Correct 417 ms 31216 KB Output is correct
84 Correct 423 ms 30520 KB Output is correct
85 Correct 278 ms 28620 KB Output is correct
86 Correct 139 ms 28532 KB Output is correct
87 Correct 144 ms 28592 KB Output is correct
88 Correct 280 ms 28068 KB Output is correct
89 Correct 268 ms 28020 KB Output is correct
90 Correct 252 ms 28404 KB Output is correct
91 Correct 289 ms 28416 KB Output is correct
92 Correct 334 ms 28512 KB Output is correct
93 Correct 391 ms 29252 KB Output is correct
94 Correct 379 ms 27876 KB Output is correct
95 Correct 264 ms 28432 KB Output is correct
96 Correct 153 ms 29364 KB Output is correct
97 Correct 126 ms 20760 KB Output is correct
98 Correct 393 ms 29572 KB Output is correct
99 Correct 257 ms 28048 KB Output is correct
100 Correct 50 ms 13916 KB Output is correct
101 Correct 326 ms 28668 KB Output is correct
102 Correct 238 ms 25124 KB Output is correct
103 Correct 194 ms 25880 KB Output is correct
104 Correct 244 ms 28156 KB Output is correct