답안 #784770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784770 2023-07-16T13:49:00 Z TheSahib Stranded Far From Home (BOI22_island) C++14
100 / 100
556 ms 83908 KB
#include <bits/stdc++.h>

#define ll long long
#define oo 1e9
#define pii pair<int, int>

using namespace std;

const int MAX = 2e5 + 5;

int n, m;
vector<int> g[MAX];
int arr[MAX];

int par[MAX];
set<int> st[MAX];
ll sum[MAX];

int findPar(int node){
    if(par[node] < 0) return node;
    return par[node] = findPar(par[node]);
}

bool unite(int v, int u){
    v = findPar(v);
    u = findPar(u);
    if(v == u) return false;
    if(-par[v] < -par[u]) swap(v, u);
    par[v] += par[u];
    par[u] = v;
    sum[v] += sum[u];
    if(st[v].size() < st[u].size()) swap(st[v], st[u]);
    for(int a:st[u]){
        st[v].insert(a);
    }
    return true;
}

bool same(int v, int u){
    return findPar(v) == findPar(u);
}

map<int, vector<int>> mp;

void solve(){
    memset(par, -1, sizeof(par));
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        mp[arr[i]].push_back(i);
        st[i].insert(i);
        sum[i] = arr[i];
    }
    
    for (int i = 1; i <= m; i++)
    {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bool ans[n + 1];
    memset(ans, 1, sizeof(ans));
    for(auto& p:mp){
        for(int node:p.second){
            for(int to:g[node]){
                if(arr[node] < arr[to]) continue;
                if(sum[findPar(to)] < arr[node] && !same(node, to)){
                    for(int a:st[findPar(to)]){
                        ans[a] = 0;
                    }
                    st[findPar(to)].clear();
                }
                unite(to, node);
            }
        }
    }
    for(int i = 1; i <= n; ++i){
        cout << ans[i];
    }
}

int main()
{
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15188 KB Output is correct
2 Correct 8 ms 15188 KB Output is correct
3 Correct 8 ms 15188 KB Output is correct
4 Correct 9 ms 15572 KB Output is correct
5 Correct 10 ms 15528 KB Output is correct
6 Correct 9 ms 15444 KB Output is correct
7 Correct 9 ms 15456 KB Output is correct
8 Correct 9 ms 15496 KB Output is correct
9 Correct 11 ms 15444 KB Output is correct
10 Correct 10 ms 15680 KB Output is correct
11 Correct 10 ms 15716 KB Output is correct
12 Correct 10 ms 15700 KB Output is correct
13 Correct 8 ms 15444 KB Output is correct
14 Correct 10 ms 15444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15188 KB Output is correct
2 Correct 8 ms 15188 KB Output is correct
3 Correct 302 ms 65728 KB Output is correct
4 Correct 243 ms 46816 KB Output is correct
5 Correct 398 ms 74124 KB Output is correct
6 Correct 425 ms 72304 KB Output is correct
7 Correct 435 ms 76704 KB Output is correct
8 Correct 347 ms 48132 KB Output is correct
9 Correct 329 ms 79852 KB Output is correct
10 Correct 310 ms 54640 KB Output is correct
11 Correct 291 ms 47896 KB Output is correct
12 Correct 281 ms 44992 KB Output is correct
13 Correct 270 ms 46652 KB Output is correct
14 Correct 210 ms 46828 KB Output is correct
15 Correct 287 ms 69256 KB Output is correct
16 Correct 264 ms 67980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15188 KB Output is correct
2 Correct 553 ms 83888 KB Output is correct
3 Correct 519 ms 78784 KB Output is correct
4 Correct 239 ms 48192 KB Output is correct
5 Correct 213 ms 46548 KB Output is correct
6 Correct 556 ms 83468 KB Output is correct
7 Correct 307 ms 69312 KB Output is correct
8 Correct 339 ms 69236 KB Output is correct
9 Correct 274 ms 68076 KB Output is correct
10 Correct 277 ms 48672 KB Output is correct
11 Correct 259 ms 46168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15188 KB Output is correct
2 Correct 386 ms 49236 KB Output is correct
3 Correct 375 ms 52472 KB Output is correct
4 Correct 407 ms 60468 KB Output is correct
5 Correct 501 ms 73516 KB Output is correct
6 Correct 417 ms 60512 KB Output is correct
7 Correct 295 ms 48824 KB Output is correct
8 Correct 192 ms 42328 KB Output is correct
9 Correct 197 ms 31952 KB Output is correct
10 Correct 456 ms 79264 KB Output is correct
11 Correct 237 ms 45424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15188 KB Output is correct
2 Correct 8 ms 15188 KB Output is correct
3 Correct 8 ms 15188 KB Output is correct
4 Correct 9 ms 15572 KB Output is correct
5 Correct 10 ms 15528 KB Output is correct
6 Correct 9 ms 15444 KB Output is correct
7 Correct 9 ms 15456 KB Output is correct
8 Correct 9 ms 15496 KB Output is correct
9 Correct 11 ms 15444 KB Output is correct
10 Correct 10 ms 15680 KB Output is correct
11 Correct 10 ms 15716 KB Output is correct
12 Correct 10 ms 15700 KB Output is correct
13 Correct 8 ms 15444 KB Output is correct
14 Correct 10 ms 15444 KB Output is correct
15 Correct 7 ms 15188 KB Output is correct
16 Correct 8 ms 15188 KB Output is correct
17 Correct 302 ms 65728 KB Output is correct
18 Correct 243 ms 46816 KB Output is correct
19 Correct 398 ms 74124 KB Output is correct
20 Correct 425 ms 72304 KB Output is correct
21 Correct 435 ms 76704 KB Output is correct
22 Correct 347 ms 48132 KB Output is correct
23 Correct 329 ms 79852 KB Output is correct
24 Correct 310 ms 54640 KB Output is correct
25 Correct 291 ms 47896 KB Output is correct
26 Correct 281 ms 44992 KB Output is correct
27 Correct 270 ms 46652 KB Output is correct
28 Correct 210 ms 46828 KB Output is correct
29 Correct 287 ms 69256 KB Output is correct
30 Correct 264 ms 67980 KB Output is correct
31 Correct 7 ms 15188 KB Output is correct
32 Correct 553 ms 83888 KB Output is correct
33 Correct 519 ms 78784 KB Output is correct
34 Correct 239 ms 48192 KB Output is correct
35 Correct 213 ms 46548 KB Output is correct
36 Correct 556 ms 83468 KB Output is correct
37 Correct 307 ms 69312 KB Output is correct
38 Correct 339 ms 69236 KB Output is correct
39 Correct 274 ms 68076 KB Output is correct
40 Correct 277 ms 48672 KB Output is correct
41 Correct 259 ms 46168 KB Output is correct
42 Correct 10 ms 15188 KB Output is correct
43 Correct 386 ms 49236 KB Output is correct
44 Correct 375 ms 52472 KB Output is correct
45 Correct 407 ms 60468 KB Output is correct
46 Correct 501 ms 73516 KB Output is correct
47 Correct 417 ms 60512 KB Output is correct
48 Correct 295 ms 48824 KB Output is correct
49 Correct 192 ms 42328 KB Output is correct
50 Correct 197 ms 31952 KB Output is correct
51 Correct 456 ms 79264 KB Output is correct
52 Correct 237 ms 45424 KB Output is correct
53 Correct 7 ms 15188 KB Output is correct
54 Correct 7 ms 15132 KB Output is correct
55 Correct 6 ms 15112 KB Output is correct
56 Correct 9 ms 15572 KB Output is correct
57 Correct 9 ms 15568 KB Output is correct
58 Correct 8 ms 15444 KB Output is correct
59 Correct 11 ms 15544 KB Output is correct
60 Correct 10 ms 15456 KB Output is correct
61 Correct 9 ms 15444 KB Output is correct
62 Correct 10 ms 15700 KB Output is correct
63 Correct 10 ms 15712 KB Output is correct
64 Correct 9 ms 15700 KB Output is correct
65 Correct 8 ms 15444 KB Output is correct
66 Correct 9 ms 15456 KB Output is correct
67 Correct 309 ms 65612 KB Output is correct
68 Correct 232 ms 46784 KB Output is correct
69 Correct 388 ms 74164 KB Output is correct
70 Correct 394 ms 72428 KB Output is correct
71 Correct 398 ms 76692 KB Output is correct
72 Correct 328 ms 48204 KB Output is correct
73 Correct 331 ms 79920 KB Output is correct
74 Correct 276 ms 54604 KB Output is correct
75 Correct 295 ms 47924 KB Output is correct
76 Correct 270 ms 44908 KB Output is correct
77 Correct 214 ms 46592 KB Output is correct
78 Correct 212 ms 46768 KB Output is correct
79 Correct 277 ms 69304 KB Output is correct
80 Correct 253 ms 68096 KB Output is correct
81 Correct 514 ms 83908 KB Output is correct
82 Correct 501 ms 78892 KB Output is correct
83 Correct 236 ms 48100 KB Output is correct
84 Correct 207 ms 46556 KB Output is correct
85 Correct 509 ms 83460 KB Output is correct
86 Correct 313 ms 69332 KB Output is correct
87 Correct 312 ms 69248 KB Output is correct
88 Correct 250 ms 48608 KB Output is correct
89 Correct 242 ms 46152 KB Output is correct
90 Correct 359 ms 49228 KB Output is correct
91 Correct 367 ms 52456 KB Output is correct
92 Correct 376 ms 60492 KB Output is correct
93 Correct 456 ms 73520 KB Output is correct
94 Correct 375 ms 60604 KB Output is correct
95 Correct 281 ms 48924 KB Output is correct
96 Correct 192 ms 42324 KB Output is correct
97 Correct 182 ms 31956 KB Output is correct
98 Correct 430 ms 79292 KB Output is correct
99 Correct 231 ms 45368 KB Output is correct
100 Correct 85 ms 19928 KB Output is correct
101 Correct 519 ms 69216 KB Output is correct
102 Correct 300 ms 48752 KB Output is correct
103 Correct 402 ms 52780 KB Output is correct
104 Correct 554 ms 66284 KB Output is correct