답안 #625273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625273 2022-08-09T18:14:36 Z Ooops_sorry Stranded Far From Home (BOI22_island) C++14
100 / 100
492 ms 77956 KB
#include<bits/stdc++.h>

using namespace std;

mt19937 rnd(51);

#define ll long long
#define pb push_back
#define ld long double

const int N = 2e5 + 10;
ll sum[N];
int par[N];
vector<int> g[N];
set<int> st[N];

int find_set(int v) {
    if (v == par[v]) {
        return v;
    } else {
        return par[v] = find_set(par[v]);
    }
}

void union_set(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (st[a].size() < st[b].size()) {
        swap(a, b);
    }
    for (auto to : st[b]) {
        st[a].insert(to);
    }
    par[b] = a;
    sum[a] += sum[b];
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for (int i = 0; i < N; i++) {
        par[i] = i;
        st[i].insert(i);
    }
    int n, m;
    cin >> n >> m;
    vector<int> s(n), good(n, 1);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sum[i] = s[i];
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int i, int j){return s[i] < s[j];});
    for (auto v : ord) {
        set<int> vert;
        for (auto to : g[v]) {
            if (s[to] <= s[v] && find_set(to) != find_set(v)) {
                vert.insert(find_set(to));
            }
        }
        for (auto to : vert) {
            if (sum[to] < s[v]) {
                for (auto u : st[to]) {
                    good[u] = 0;
                }
                st[to].clear();
            }
            union_set(to, v);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << good[i];
    }
    cout << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24532 KB Output is correct
2 Correct 19 ms 24564 KB Output is correct
3 Correct 28 ms 24524 KB Output is correct
4 Correct 22 ms 24660 KB Output is correct
5 Correct 25 ms 24780 KB Output is correct
6 Correct 21 ms 24804 KB Output is correct
7 Correct 20 ms 24712 KB Output is correct
8 Correct 20 ms 24616 KB Output is correct
9 Correct 21 ms 24788 KB Output is correct
10 Correct 24 ms 24844 KB Output is correct
11 Correct 22 ms 24788 KB Output is correct
12 Correct 22 ms 24856 KB Output is correct
13 Correct 21 ms 24916 KB Output is correct
14 Correct 22 ms 24732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24532 KB Output is correct
2 Correct 21 ms 24500 KB Output is correct
3 Correct 183 ms 41948 KB Output is correct
4 Correct 313 ms 72436 KB Output is correct
5 Correct 374 ms 54628 KB Output is correct
6 Correct 294 ms 56832 KB Output is correct
7 Correct 363 ms 56388 KB Output is correct
8 Correct 377 ms 64692 KB Output is correct
9 Correct 302 ms 64444 KB Output is correct
10 Correct 240 ms 48656 KB Output is correct
11 Correct 170 ms 48484 KB Output is correct
12 Correct 313 ms 51096 KB Output is correct
13 Correct 315 ms 76412 KB Output is correct
14 Correct 272 ms 74548 KB Output is correct
15 Correct 230 ms 48924 KB Output is correct
16 Correct 147 ms 47888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24532 KB Output is correct
2 Correct 360 ms 59756 KB Output is correct
3 Correct 358 ms 59724 KB Output is correct
4 Correct 288 ms 74292 KB Output is correct
5 Correct 302 ms 74040 KB Output is correct
6 Correct 333 ms 62888 KB Output is correct
7 Correct 232 ms 48740 KB Output is correct
8 Correct 265 ms 48864 KB Output is correct
9 Correct 148 ms 47844 KB Output is correct
10 Correct 229 ms 52892 KB Output is correct
11 Correct 302 ms 64768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 24560 KB Output is correct
2 Correct 343 ms 45400 KB Output is correct
3 Correct 395 ms 49368 KB Output is correct
4 Correct 367 ms 56472 KB Output is correct
5 Correct 492 ms 70452 KB Output is correct
6 Correct 362 ms 57500 KB Output is correct
7 Correct 179 ms 47376 KB Output is correct
8 Correct 201 ms 53892 KB Output is correct
9 Correct 171 ms 37016 KB Output is correct
10 Correct 466 ms 76988 KB Output is correct
11 Correct 288 ms 65860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24532 KB Output is correct
2 Correct 19 ms 24564 KB Output is correct
3 Correct 28 ms 24524 KB Output is correct
4 Correct 22 ms 24660 KB Output is correct
5 Correct 25 ms 24780 KB Output is correct
6 Correct 21 ms 24804 KB Output is correct
7 Correct 20 ms 24712 KB Output is correct
8 Correct 20 ms 24616 KB Output is correct
9 Correct 21 ms 24788 KB Output is correct
10 Correct 24 ms 24844 KB Output is correct
11 Correct 22 ms 24788 KB Output is correct
12 Correct 22 ms 24856 KB Output is correct
13 Correct 21 ms 24916 KB Output is correct
14 Correct 22 ms 24732 KB Output is correct
15 Correct 20 ms 24532 KB Output is correct
16 Correct 21 ms 24500 KB Output is correct
17 Correct 183 ms 41948 KB Output is correct
18 Correct 313 ms 72436 KB Output is correct
19 Correct 374 ms 54628 KB Output is correct
20 Correct 294 ms 56832 KB Output is correct
21 Correct 363 ms 56388 KB Output is correct
22 Correct 377 ms 64692 KB Output is correct
23 Correct 302 ms 64444 KB Output is correct
24 Correct 240 ms 48656 KB Output is correct
25 Correct 170 ms 48484 KB Output is correct
26 Correct 313 ms 51096 KB Output is correct
27 Correct 315 ms 76412 KB Output is correct
28 Correct 272 ms 74548 KB Output is correct
29 Correct 230 ms 48924 KB Output is correct
30 Correct 147 ms 47888 KB Output is correct
31 Correct 20 ms 24532 KB Output is correct
32 Correct 360 ms 59756 KB Output is correct
33 Correct 358 ms 59724 KB Output is correct
34 Correct 288 ms 74292 KB Output is correct
35 Correct 302 ms 74040 KB Output is correct
36 Correct 333 ms 62888 KB Output is correct
37 Correct 232 ms 48740 KB Output is correct
38 Correct 265 ms 48864 KB Output is correct
39 Correct 148 ms 47844 KB Output is correct
40 Correct 229 ms 52892 KB Output is correct
41 Correct 302 ms 64768 KB Output is correct
42 Correct 19 ms 24560 KB Output is correct
43 Correct 343 ms 45400 KB Output is correct
44 Correct 395 ms 49368 KB Output is correct
45 Correct 367 ms 56472 KB Output is correct
46 Correct 492 ms 70452 KB Output is correct
47 Correct 362 ms 57500 KB Output is correct
48 Correct 179 ms 47376 KB Output is correct
49 Correct 201 ms 53892 KB Output is correct
50 Correct 171 ms 37016 KB Output is correct
51 Correct 466 ms 76988 KB Output is correct
52 Correct 288 ms 65860 KB Output is correct
53 Correct 20 ms 24512 KB Output is correct
54 Correct 19 ms 24564 KB Output is correct
55 Correct 20 ms 24556 KB Output is correct
56 Correct 22 ms 24808 KB Output is correct
57 Correct 23 ms 24788 KB Output is correct
58 Correct 21 ms 24812 KB Output is correct
59 Correct 21 ms 24648 KB Output is correct
60 Correct 21 ms 24652 KB Output is correct
61 Correct 26 ms 24704 KB Output is correct
62 Correct 24 ms 24780 KB Output is correct
63 Correct 22 ms 24776 KB Output is correct
64 Correct 21 ms 24740 KB Output is correct
65 Correct 21 ms 24872 KB Output is correct
66 Correct 21 ms 24736 KB Output is correct
67 Correct 194 ms 45764 KB Output is correct
68 Correct 304 ms 74744 KB Output is correct
69 Correct 325 ms 54800 KB Output is correct
70 Correct 310 ms 56780 KB Output is correct
71 Correct 299 ms 56400 KB Output is correct
72 Correct 358 ms 64656 KB Output is correct
73 Correct 259 ms 64596 KB Output is correct
74 Correct 213 ms 48748 KB Output is correct
75 Correct 155 ms 48544 KB Output is correct
76 Correct 284 ms 51036 KB Output is correct
77 Correct 281 ms 76356 KB Output is correct
78 Correct 272 ms 74468 KB Output is correct
79 Correct 194 ms 48744 KB Output is correct
80 Correct 142 ms 47828 KB Output is correct
81 Correct 361 ms 63588 KB Output is correct
82 Correct 343 ms 63464 KB Output is correct
83 Correct 286 ms 77956 KB Output is correct
84 Correct 278 ms 76112 KB Output is correct
85 Correct 336 ms 62892 KB Output is correct
86 Correct 240 ms 48736 KB Output is correct
87 Correct 240 ms 48840 KB Output is correct
88 Correct 217 ms 52816 KB Output is correct
89 Correct 288 ms 64844 KB Output is correct
90 Correct 379 ms 49180 KB Output is correct
91 Correct 339 ms 53104 KB Output is correct
92 Correct 394 ms 60176 KB Output is correct
93 Correct 489 ms 74024 KB Output is correct
94 Correct 397 ms 61060 KB Output is correct
95 Correct 179 ms 50888 KB Output is correct
96 Correct 222 ms 56444 KB Output is correct
97 Correct 175 ms 37068 KB Output is correct
98 Correct 431 ms 76920 KB Output is correct
99 Correct 299 ms 65840 KB Output is correct
100 Correct 61 ms 28768 KB Output is correct
101 Correct 374 ms 53676 KB Output is correct
102 Correct 301 ms 50804 KB Output is correct
103 Correct 290 ms 41576 KB Output is correct
104 Correct 353 ms 46520 KB Output is correct