답안 #869479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869479 2023-11-04T12:19:52 Z lolismek Stranded Far From Home (BOI22_island) C++14
100 / 100
266 ms 37308 KB
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>

#define int long long
#define pii pair <int, int>

using namespace std;

//ifstream fin("input.in");
//ofstream fout("output.out");

#define fin cin
#define fout cout

const int NMAX = 2e5;

int v[NMAX + 1];
vector <int> adj[NMAX + 1];

int par[NMAX + 1];
int sum[NMAX + 1];

bool bad[NMAX + 1];
int Find(int x){
    if(x == par[x]){
        return x;
    }
    int y = Find(par[x]); // ?
    bad[x] |= bad[par[x]];
    par[x] = y;
    return par[x];
}

void Join(int x, int y){
    x = Find(x);
    y = Find(y);

    if(x == y){
        return;
    }

    if(v[x] < v[y]){
        swap(x, y);
    }

    if(v[x] > sum[y]){
        bad[y] = 1;
    }

    par[y] = x;
    sum[x] += sum[y];
}

bool ins[NMAX + 1];

void Insert(int x){
    ins[x] = true;
    for(int vec : adj[x]){
        if(ins[vec]){
            Join(vec, x);
        }
    }
}

vector <int> inds[NMAX + 1];

pii e[NMAX + 1];

signed main(){

    int n, m;
    cin >> n >> m;

    vector <int> vals;
    for(int i = 1; i <= n; i++){
        cin >> v[i];
        par[i] = i;
        sum[i] = v[i];
        vals.push_back(v[i]);
    }

    vector <pii> aux;
    for(int i = 1; i <= m; i++){
        int a, b;
        fin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        e[i] = {a, b};
        aux.push_back({max(v[a], v[b]), i});
    }

    sort(aux.begin(), aux.end());

    for(pii x : aux){
        Join(e[x.second].first, e[x.second].second);
    }

    for(int i = 1; i <= n; i++){
        Find(i);
        cout << !bad[i];
    }
    cout << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 15192 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14940 KB Output is correct
12 Correct 4 ms 14940 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 240 ms 30356 KB Output is correct
4 Correct 171 ms 30036 KB Output is correct
5 Correct 219 ms 30420 KB Output is correct
6 Correct 218 ms 30656 KB Output is correct
7 Correct 210 ms 30892 KB Output is correct
8 Correct 216 ms 30288 KB Output is correct
9 Correct 209 ms 32100 KB Output is correct
10 Correct 165 ms 30764 KB Output is correct
11 Correct 163 ms 33212 KB Output is correct
12 Correct 178 ms 30732 KB Output is correct
13 Correct 184 ms 29632 KB Output is correct
14 Correct 168 ms 31136 KB Output is correct
15 Correct 221 ms 29600 KB Output is correct
16 Correct 156 ms 28856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 212 ms 29216 KB Output is correct
3 Correct 213 ms 30620 KB Output is correct
4 Correct 200 ms 29884 KB Output is correct
5 Correct 174 ms 30596 KB Output is correct
6 Correct 235 ms 29188 KB Output is correct
7 Correct 208 ms 29556 KB Output is correct
8 Correct 213 ms 29376 KB Output is correct
9 Correct 157 ms 28860 KB Output is correct
10 Correct 178 ms 29632 KB Output is correct
11 Correct 180 ms 30188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 220 ms 30080 KB Output is correct
3 Correct 233 ms 34864 KB Output is correct
4 Correct 264 ms 34504 KB Output is correct
5 Correct 206 ms 35520 KB Output is correct
6 Correct 209 ms 34748 KB Output is correct
7 Correct 187 ms 37060 KB Output is correct
8 Correct 159 ms 35520 KB Output is correct
9 Correct 198 ms 29836 KB Output is correct
10 Correct 185 ms 33000 KB Output is correct
11 Correct 178 ms 32188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 15192 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14940 KB Output is correct
12 Correct 4 ms 14940 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 14940 KB Output is correct
15 Correct 2 ms 14684 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 240 ms 30356 KB Output is correct
18 Correct 171 ms 30036 KB Output is correct
19 Correct 219 ms 30420 KB Output is correct
20 Correct 218 ms 30656 KB Output is correct
21 Correct 210 ms 30892 KB Output is correct
22 Correct 216 ms 30288 KB Output is correct
23 Correct 209 ms 32100 KB Output is correct
24 Correct 165 ms 30764 KB Output is correct
25 Correct 163 ms 33212 KB Output is correct
26 Correct 178 ms 30732 KB Output is correct
27 Correct 184 ms 29632 KB Output is correct
28 Correct 168 ms 31136 KB Output is correct
29 Correct 221 ms 29600 KB Output is correct
30 Correct 156 ms 28856 KB Output is correct
31 Correct 2 ms 14684 KB Output is correct
32 Correct 212 ms 29216 KB Output is correct
33 Correct 213 ms 30620 KB Output is correct
34 Correct 200 ms 29884 KB Output is correct
35 Correct 174 ms 30596 KB Output is correct
36 Correct 235 ms 29188 KB Output is correct
37 Correct 208 ms 29556 KB Output is correct
38 Correct 213 ms 29376 KB Output is correct
39 Correct 157 ms 28860 KB Output is correct
40 Correct 178 ms 29632 KB Output is correct
41 Correct 180 ms 30188 KB Output is correct
42 Correct 2 ms 14684 KB Output is correct
43 Correct 220 ms 30080 KB Output is correct
44 Correct 233 ms 34864 KB Output is correct
45 Correct 264 ms 34504 KB Output is correct
46 Correct 206 ms 35520 KB Output is correct
47 Correct 209 ms 34748 KB Output is correct
48 Correct 187 ms 37060 KB Output is correct
49 Correct 159 ms 35520 KB Output is correct
50 Correct 198 ms 29836 KB Output is correct
51 Correct 185 ms 33000 KB Output is correct
52 Correct 178 ms 32188 KB Output is correct
53 Correct 3 ms 14684 KB Output is correct
54 Correct 3 ms 14684 KB Output is correct
55 Correct 3 ms 14684 KB Output is correct
56 Correct 5 ms 14940 KB Output is correct
57 Correct 4 ms 14936 KB Output is correct
58 Correct 4 ms 14940 KB Output is correct
59 Correct 4 ms 14940 KB Output is correct
60 Correct 4 ms 14940 KB Output is correct
61 Correct 4 ms 14940 KB Output is correct
62 Correct 4 ms 14940 KB Output is correct
63 Correct 5 ms 14940 KB Output is correct
64 Correct 5 ms 14940 KB Output is correct
65 Correct 4 ms 14940 KB Output is correct
66 Correct 4 ms 14940 KB Output is correct
67 Correct 211 ms 34484 KB Output is correct
68 Correct 216 ms 33212 KB Output is correct
69 Correct 218 ms 35008 KB Output is correct
70 Correct 219 ms 34388 KB Output is correct
71 Correct 213 ms 34752 KB Output is correct
72 Correct 204 ms 35176 KB Output is correct
73 Correct 248 ms 35832 KB Output is correct
74 Correct 187 ms 34188 KB Output is correct
75 Correct 186 ms 37308 KB Output is correct
76 Correct 191 ms 33072 KB Output is correct
77 Correct 179 ms 33060 KB Output is correct
78 Correct 173 ms 32108 KB Output is correct
79 Correct 244 ms 34600 KB Output is correct
80 Correct 156 ms 32696 KB Output is correct
81 Correct 224 ms 33468 KB Output is correct
82 Correct 235 ms 34292 KB Output is correct
83 Correct 210 ms 33464 KB Output is correct
84 Correct 180 ms 33356 KB Output is correct
85 Correct 237 ms 34424 KB Output is correct
86 Correct 207 ms 34616 KB Output is correct
87 Correct 235 ms 34240 KB Output is correct
88 Correct 187 ms 32820 KB Output is correct
89 Correct 183 ms 32188 KB Output is correct
90 Correct 234 ms 34496 KB Output is correct
91 Correct 232 ms 34376 KB Output is correct
92 Correct 253 ms 35260 KB Output is correct
93 Correct 227 ms 34476 KB Output is correct
94 Correct 205 ms 34952 KB Output is correct
95 Correct 204 ms 37132 KB Output is correct
96 Correct 167 ms 36028 KB Output is correct
97 Correct 154 ms 29624 KB Output is correct
98 Correct 171 ms 33560 KB Output is correct
99 Correct 198 ms 32424 KB Output is correct
100 Correct 105 ms 27596 KB Output is correct
101 Correct 266 ms 34752 KB Output is correct
102 Correct 199 ms 33036 KB Output is correct
103 Correct 245 ms 33732 KB Output is correct
104 Correct 260 ms 34492 KB Output is correct