답안 #733429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733429 2023-04-30T17:12:25 Z speedyArda Stranded Far From Home (BOI22_island) C++14
100 / 100
343 ms 22084 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const int MAXN = 2e5+5;
ll in[MAXN], sum[MAXN];
int par[MAXN];
bool marked[MAXN];
int find(int v)
{
    int curr_par = v;
    while(curr_par != par[curr_par])
    {
        if(marked[curr_par])
            marked[v] = true;
        curr_par = par[curr_par];
    }
    return curr_par;

}


void merge(int a, int b)
{
    a = find(a), b = find(b);
    if(a == b)
        return ;
    if(sum[a] < sum[b])
        swap(a, b);
    sum[a] += sum[b];
    sum[b] = 0;
    par[b] = a;
}
vector < vector< int > > adj(MAXN);
int main() 
{

    int n, m;
    cin >> n >> m;
    vector < pair<int, int> > sorted;
    for(int i = 1; i <= n; i++) {
        cin >> in[i];
        sorted.push_back({in[i], i});
        sum[i] = in[i];
        par[i] = i;
    }
    sort(sorted.begin(), sorted.end());
    for(int i = 1; i <= m; i++)
    {
        int f, s;
        cin >> f >> s;
        adj[f].push_back(s);
        adj[s].push_back(f);
    }

    for(int i = 0; i < n; i++) 
    {
        int idx = sorted[i].second;
        for(int e : adj[idx])
        {
            if(in[e] <= in[idx]) {
                int other = find(e);
                if(sum[other] < in[idx])
                    marked[other] = true;
                merge(other, idx);
            }
        }

    }

    for(int i = 1; i <= n; i++)
    {
        find(i);
        cout << !marked[i];
    }

    cout << "\n";

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 6 ms 5076 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 5 ms 5076 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 5 ms 5076 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 5 ms 5076 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 256 ms 17212 KB Output is correct
4 Correct 208 ms 17016 KB Output is correct
5 Correct 250 ms 16776 KB Output is correct
6 Correct 343 ms 21500 KB Output is correct
7 Correct 282 ms 21472 KB Output is correct
8 Correct 273 ms 21332 KB Output is correct
9 Correct 275 ms 21328 KB Output is correct
10 Correct 221 ms 21464 KB Output is correct
11 Correct 230 ms 21152 KB Output is correct
12 Correct 237 ms 20160 KB Output is correct
13 Correct 218 ms 20168 KB Output is correct
14 Correct 225 ms 20184 KB Output is correct
15 Correct 278 ms 21368 KB Output is correct
16 Correct 187 ms 20472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 285 ms 16996 KB Output is correct
3 Correct 295 ms 21572 KB Output is correct
4 Correct 267 ms 21300 KB Output is correct
5 Correct 220 ms 20004 KB Output is correct
6 Correct 296 ms 21676 KB Output is correct
7 Correct 285 ms 21404 KB Output is correct
8 Correct 271 ms 21376 KB Output is correct
9 Correct 191 ms 20540 KB Output is correct
10 Correct 234 ms 20980 KB Output is correct
11 Correct 239 ms 20028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 302 ms 17116 KB Output is correct
3 Correct 303 ms 17144 KB Output is correct
4 Correct 309 ms 17128 KB Output is correct
5 Correct 302 ms 16964 KB Output is correct
6 Correct 268 ms 16496 KB Output is correct
7 Correct 245 ms 17728 KB Output is correct
8 Correct 181 ms 16992 KB Output is correct
9 Correct 177 ms 12044 KB Output is correct
10 Correct 239 ms 17148 KB Output is correct
11 Correct 237 ms 17068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 6 ms 5076 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 5 ms 5076 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 5 ms 5076 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 5 ms 5076 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 256 ms 17212 KB Output is correct
18 Correct 208 ms 17016 KB Output is correct
19 Correct 250 ms 16776 KB Output is correct
20 Correct 343 ms 21500 KB Output is correct
21 Correct 282 ms 21472 KB Output is correct
22 Correct 273 ms 21332 KB Output is correct
23 Correct 275 ms 21328 KB Output is correct
24 Correct 221 ms 21464 KB Output is correct
25 Correct 230 ms 21152 KB Output is correct
26 Correct 237 ms 20160 KB Output is correct
27 Correct 218 ms 20168 KB Output is correct
28 Correct 225 ms 20184 KB Output is correct
29 Correct 278 ms 21368 KB Output is correct
30 Correct 187 ms 20472 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 285 ms 16996 KB Output is correct
33 Correct 295 ms 21572 KB Output is correct
34 Correct 267 ms 21300 KB Output is correct
35 Correct 220 ms 20004 KB Output is correct
36 Correct 296 ms 21676 KB Output is correct
37 Correct 285 ms 21404 KB Output is correct
38 Correct 271 ms 21376 KB Output is correct
39 Correct 191 ms 20540 KB Output is correct
40 Correct 234 ms 20980 KB Output is correct
41 Correct 239 ms 20028 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 302 ms 17116 KB Output is correct
44 Correct 303 ms 17144 KB Output is correct
45 Correct 309 ms 17128 KB Output is correct
46 Correct 302 ms 16964 KB Output is correct
47 Correct 268 ms 16496 KB Output is correct
48 Correct 245 ms 17728 KB Output is correct
49 Correct 181 ms 16992 KB Output is correct
50 Correct 177 ms 12044 KB Output is correct
51 Correct 239 ms 17148 KB Output is correct
52 Correct 237 ms 17068 KB Output is correct
53 Correct 3 ms 5024 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 5016 KB Output is correct
56 Correct 6 ms 5076 KB Output is correct
57 Correct 5 ms 5076 KB Output is correct
58 Correct 5 ms 5076 KB Output is correct
59 Correct 5 ms 5116 KB Output is correct
60 Correct 5 ms 5032 KB Output is correct
61 Correct 5 ms 5076 KB Output is correct
62 Correct 5 ms 5076 KB Output is correct
63 Correct 5 ms 5076 KB Output is correct
64 Correct 5 ms 5164 KB Output is correct
65 Correct 4 ms 5160 KB Output is correct
66 Correct 5 ms 5076 KB Output is correct
67 Correct 278 ms 21476 KB Output is correct
68 Correct 222 ms 20180 KB Output is correct
69 Correct 287 ms 21136 KB Output is correct
70 Correct 298 ms 21460 KB Output is correct
71 Correct 294 ms 21432 KB Output is correct
72 Correct 291 ms 21396 KB Output is correct
73 Correct 275 ms 21376 KB Output is correct
74 Correct 220 ms 21436 KB Output is correct
75 Correct 238 ms 21120 KB Output is correct
76 Correct 241 ms 20148 KB Output is correct
77 Correct 231 ms 20048 KB Output is correct
78 Correct 227 ms 20104 KB Output is correct
79 Correct 261 ms 21372 KB Output is correct
80 Correct 197 ms 20588 KB Output is correct
81 Correct 300 ms 21464 KB Output is correct
82 Correct 294 ms 21464 KB Output is correct
83 Correct 302 ms 21484 KB Output is correct
84 Correct 240 ms 19956 KB Output is correct
85 Correct 319 ms 21504 KB Output is correct
86 Correct 273 ms 21400 KB Output is correct
87 Correct 285 ms 21436 KB Output is correct
88 Correct 245 ms 20800 KB Output is correct
89 Correct 246 ms 20116 KB Output is correct
90 Correct 322 ms 21516 KB Output is correct
91 Correct 303 ms 21568 KB Output is correct
92 Correct 308 ms 21680 KB Output is correct
93 Correct 297 ms 21444 KB Output is correct
94 Correct 283 ms 20668 KB Output is correct
95 Correct 240 ms 22084 KB Output is correct
96 Correct 188 ms 20256 KB Output is correct
97 Correct 200 ms 14696 KB Output is correct
98 Correct 257 ms 20056 KB Output is correct
99 Correct 244 ms 19992 KB Output is correct
100 Correct 102 ms 9224 KB Output is correct
101 Correct 319 ms 21528 KB Output is correct
102 Correct 260 ms 18500 KB Output is correct
103 Correct 282 ms 19232 KB Output is correct
104 Correct 304 ms 21408 KB Output is correct