Submission #579826

# Submission time Handle Problem Language Result Execution time Memory
579826 2022-06-20T03:22:05 Z balbit Stranded Far From Home (BOI22_island) C++14
100 / 100
278 ms 44208 KB
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define pii pair<ll, ll>
#define f first
#define s second

#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

#define MX(a,b) a=max(a,b)
#define MN(a,b) a = min(a,b)
#define FOR(i,a,b) for (int i = a; i<b; ++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT

const int maxn = 2e5+5;
vector<int> alive[maxn];
int S[maxn];
int iv[maxn];
int par[maxn];

vector<int> g[maxn];

int find(int x) { return x == par[x]? x : par[x] = find(par[x]);}


void test(int p, int rnd) {
    p = find(p);
    if (S[p] < rnd) {
        alive[p].clear();
    }
}

void mrg(int a, int b, int t) {
    bug("mrg", a,b,t);
    a = find(a); b =find(b);
    if (a == b) return;
    test(a,t); test(b,t);
    if (SZ(alive[a]) < SZ(alive[b])) swap(a,b);
    // a is bigger
    alive[a].insert(alive[a].end(), ALL(alive[b]));
    par[b] = a;
    S[a] += S[b];
}

signed main(){
    ios::sync_with_stdio(0), cin.tie(0);

    bug(1,2);

    int n,m;
    cin>>n>>m;
    vector<pii> go;
    REP(i,n) {
        cin>>S[i]; iv[i] = S[i]; go.pb({S[i], i});
        alive[i].pb(i);
        par[i] = i;
    }
    REP(i,m) {
        int a,b; cin>>a>>b; --a; --b;
        g[a].pb(b); g[b].pb(a);
    }
    sort(ALL(go));
    for (pii p : go) {
        int who = p.s, val = p.f;
        for (int u : g[who]) {
            if (iv[u] <= val) mrg(who, u, val);
        }
    }
    vector<int> ret(n);
    for (int e : alive[find(0)]) ret[e] = 1;
    REP(i,n) cout<<ret[i];
    cout<<endl;

}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 8 ms 9940 KB Output is correct
5 Correct 7 ms 9992 KB Output is correct
6 Correct 6 ms 9888 KB Output is correct
7 Correct 6 ms 9940 KB Output is correct
8 Correct 6 ms 9808 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 6 ms 9964 KB Output is correct
11 Correct 6 ms 9940 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 6 ms 9892 KB Output is correct
14 Correct 6 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9624 KB Output is correct
3 Correct 185 ms 35880 KB Output is correct
4 Correct 213 ms 36264 KB Output is correct
5 Correct 172 ms 38700 KB Output is correct
6 Correct 216 ms 40388 KB Output is correct
7 Correct 208 ms 40072 KB Output is correct
8 Correct 202 ms 34812 KB Output is correct
9 Correct 202 ms 42848 KB Output is correct
10 Correct 170 ms 33328 KB Output is correct
11 Correct 195 ms 35448 KB Output is correct
12 Correct 201 ms 35176 KB Output is correct
13 Correct 217 ms 33804 KB Output is correct
14 Correct 171 ms 35300 KB Output is correct
15 Correct 168 ms 33856 KB Output is correct
16 Correct 105 ms 33620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 224 ms 40120 KB Output is correct
3 Correct 230 ms 39740 KB Output is correct
4 Correct 196 ms 33840 KB Output is correct
5 Correct 160 ms 34888 KB Output is correct
6 Correct 214 ms 40244 KB Output is correct
7 Correct 181 ms 33840 KB Output is correct
8 Correct 197 ms 33868 KB Output is correct
9 Correct 104 ms 33616 KB Output is correct
10 Correct 162 ms 33660 KB Output is correct
11 Correct 209 ms 35504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 278 ms 36624 KB Output is correct
3 Correct 254 ms 37636 KB Output is correct
4 Correct 248 ms 39756 KB Output is correct
5 Correct 228 ms 40760 KB Output is correct
6 Correct 252 ms 36964 KB Output is correct
7 Correct 205 ms 35424 KB Output is correct
8 Correct 104 ms 35908 KB Output is correct
9 Correct 134 ms 24976 KB Output is correct
10 Correct 273 ms 44208 KB Output is correct
11 Correct 183 ms 35752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 8 ms 9940 KB Output is correct
5 Correct 7 ms 9992 KB Output is correct
6 Correct 6 ms 9888 KB Output is correct
7 Correct 6 ms 9940 KB Output is correct
8 Correct 6 ms 9808 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 6 ms 9964 KB Output is correct
11 Correct 6 ms 9940 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 6 ms 9892 KB Output is correct
14 Correct 6 ms 9940 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9624 KB Output is correct
17 Correct 185 ms 35880 KB Output is correct
18 Correct 213 ms 36264 KB Output is correct
19 Correct 172 ms 38700 KB Output is correct
20 Correct 216 ms 40388 KB Output is correct
21 Correct 208 ms 40072 KB Output is correct
22 Correct 202 ms 34812 KB Output is correct
23 Correct 202 ms 42848 KB Output is correct
24 Correct 170 ms 33328 KB Output is correct
25 Correct 195 ms 35448 KB Output is correct
26 Correct 201 ms 35176 KB Output is correct
27 Correct 217 ms 33804 KB Output is correct
28 Correct 171 ms 35300 KB Output is correct
29 Correct 168 ms 33856 KB Output is correct
30 Correct 105 ms 33620 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 224 ms 40120 KB Output is correct
33 Correct 230 ms 39740 KB Output is correct
34 Correct 196 ms 33840 KB Output is correct
35 Correct 160 ms 34888 KB Output is correct
36 Correct 214 ms 40244 KB Output is correct
37 Correct 181 ms 33840 KB Output is correct
38 Correct 197 ms 33868 KB Output is correct
39 Correct 104 ms 33616 KB Output is correct
40 Correct 162 ms 33660 KB Output is correct
41 Correct 209 ms 35504 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 278 ms 36624 KB Output is correct
44 Correct 254 ms 37636 KB Output is correct
45 Correct 248 ms 39756 KB Output is correct
46 Correct 228 ms 40760 KB Output is correct
47 Correct 252 ms 36964 KB Output is correct
48 Correct 205 ms 35424 KB Output is correct
49 Correct 104 ms 35908 KB Output is correct
50 Correct 134 ms 24976 KB Output is correct
51 Correct 273 ms 44208 KB Output is correct
52 Correct 183 ms 35752 KB Output is correct
53 Correct 6 ms 9620 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 6 ms 9940 KB Output is correct
57 Correct 7 ms 9940 KB Output is correct
58 Correct 7 ms 9912 KB Output is correct
59 Correct 6 ms 9940 KB Output is correct
60 Correct 6 ms 9812 KB Output is correct
61 Correct 6 ms 9940 KB Output is correct
62 Correct 9 ms 9940 KB Output is correct
63 Correct 7 ms 9940 KB Output is correct
64 Correct 7 ms 9940 KB Output is correct
65 Correct 6 ms 9940 KB Output is correct
66 Correct 7 ms 9940 KB Output is correct
67 Correct 182 ms 35984 KB Output is correct
68 Correct 174 ms 36268 KB Output is correct
69 Correct 223 ms 38704 KB Output is correct
70 Correct 188 ms 40368 KB Output is correct
71 Correct 196 ms 40152 KB Output is correct
72 Correct 211 ms 34912 KB Output is correct
73 Correct 179 ms 42956 KB Output is correct
74 Correct 152 ms 33328 KB Output is correct
75 Correct 184 ms 35424 KB Output is correct
76 Correct 209 ms 35188 KB Output is correct
77 Correct 175 ms 33852 KB Output is correct
78 Correct 190 ms 35292 KB Output is correct
79 Correct 172 ms 33888 KB Output is correct
80 Correct 105 ms 33644 KB Output is correct
81 Correct 263 ms 39996 KB Output is correct
82 Correct 221 ms 39800 KB Output is correct
83 Correct 182 ms 33768 KB Output is correct
84 Correct 165 ms 34864 KB Output is correct
85 Correct 222 ms 40268 KB Output is correct
86 Correct 169 ms 33836 KB Output is correct
87 Correct 174 ms 33808 KB Output is correct
88 Correct 165 ms 33580 KB Output is correct
89 Correct 245 ms 35540 KB Output is correct
90 Correct 230 ms 36616 KB Output is correct
91 Correct 213 ms 37584 KB Output is correct
92 Correct 231 ms 39768 KB Output is correct
93 Correct 239 ms 40688 KB Output is correct
94 Correct 262 ms 36884 KB Output is correct
95 Correct 162 ms 35388 KB Output is correct
96 Correct 106 ms 35968 KB Output is correct
97 Correct 128 ms 25016 KB Output is correct
98 Correct 226 ms 44044 KB Output is correct
99 Correct 182 ms 35888 KB Output is correct
100 Correct 43 ms 14472 KB Output is correct
101 Correct 229 ms 37952 KB Output is correct
102 Correct 200 ms 31756 KB Output is correct
103 Correct 203 ms 31924 KB Output is correct
104 Correct 250 ms 36304 KB Output is correct