답안 #602209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602209 2022-07-22T17:16:52 Z Vanilla Stranded Far From Home (BOI22_island) C++17
100 / 100
364 ms 35044 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 2e5 + 2;
int a[maxn], dsu[maxn];
int64 sum[maxn];
vector <int> ad [maxn];
vector <int> comp [maxn];
int rs [maxn];

int dad (int x) {
    return dsu[x] = (x == dsu[x] ? x: dad(dsu[x]));
}

int main() {
    int n,m;
    cin >> n >> m;
    vector <pair <int, int> > v;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        dsu[i] = i;
        sum[i] = a[i];
        comp[i].push_back(i);
        v.push_back({a[i], i});
    }
    for (int i = 1; i <= m; i++){
        int x,y;
        cin >> x >> y;
        if (a[x] < a[y]) swap(x,y);
        ad[x].push_back(y);
    }
    sort(v.begin(), v.end());
    for (auto [val, x]: v) {
        for (auto y: ad[x]) {
            if (a[y] > a[x]) continue;
            int p1 = dad(x), p2 = dad(y);
            if (val > sum[p2]) comp[p2].clear();
            if (p1 != p2) {
                if (comp[p1].size() < comp[p2].size()) swap(p1, p2);
                dsu[p2] = p1;
                sum[p1] += sum[p2];
                while (!comp[p2].empty()) {
                    comp[p1].push_back(comp[p2].back());
                    comp[p2].pop_back();
                }
            }
            ad[x].pop_back();
        }
    }
    map <int, int> dd;
    for (int i = 1; i <= n; i++){
        if (!dd.count(dad(i))) {
            dd[dad(i)] = 1;
            for (int j: comp[dad(i)]) rs[j] = 1;
        }
    }
    for (int i = 1; i <= n; i++) cout << rs[i] << "";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 8 ms 9860 KB Output is correct
5 Correct 8 ms 9812 KB Output is correct
6 Correct 8 ms 9832 KB Output is correct
7 Correct 7 ms 9800 KB Output is correct
8 Correct 6 ms 9804 KB Output is correct
9 Correct 7 ms 9812 KB Output is correct
10 Correct 8 ms 9812 KB Output is correct
11 Correct 10 ms 9796 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
13 Correct 7 ms 9812 KB Output is correct
14 Correct 7 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 322 ms 27404 KB Output is correct
4 Correct 210 ms 27032 KB Output is correct
5 Correct 266 ms 28296 KB Output is correct
6 Correct 274 ms 28804 KB Output is correct
7 Correct 273 ms 28816 KB Output is correct
8 Correct 357 ms 27708 KB Output is correct
9 Correct 243 ms 28728 KB Output is correct
10 Correct 195 ms 22608 KB Output is correct
11 Correct 253 ms 26892 KB Output is correct
12 Correct 231 ms 26240 KB Output is correct
13 Correct 216 ms 27324 KB Output is correct
14 Correct 252 ms 27296 KB Output is correct
15 Correct 256 ms 29768 KB Output is correct
16 Correct 202 ms 29512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 349 ms 29732 KB Output is correct
3 Correct 364 ms 32616 KB Output is correct
4 Correct 300 ms 32196 KB Output is correct
5 Correct 236 ms 29808 KB Output is correct
6 Correct 334 ms 33028 KB Output is correct
7 Correct 295 ms 33284 KB Output is correct
8 Correct 270 ms 32924 KB Output is correct
9 Correct 210 ms 32044 KB Output is correct
10 Correct 262 ms 27408 KB Output is correct
11 Correct 234 ms 29368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 336 ms 27460 KB Output is correct
3 Correct 313 ms 32080 KB Output is correct
4 Correct 322 ms 30564 KB Output is correct
5 Correct 327 ms 35044 KB Output is correct
6 Correct 296 ms 31896 KB Output is correct
7 Correct 265 ms 31148 KB Output is correct
8 Correct 197 ms 31232 KB Output is correct
9 Correct 197 ms 21404 KB Output is correct
10 Correct 267 ms 32720 KB Output is correct
11 Correct 256 ms 28528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 8 ms 9860 KB Output is correct
5 Correct 8 ms 9812 KB Output is correct
6 Correct 8 ms 9832 KB Output is correct
7 Correct 7 ms 9800 KB Output is correct
8 Correct 6 ms 9804 KB Output is correct
9 Correct 7 ms 9812 KB Output is correct
10 Correct 8 ms 9812 KB Output is correct
11 Correct 10 ms 9796 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
13 Correct 7 ms 9812 KB Output is correct
14 Correct 7 ms 9812 KB Output is correct
15 Correct 7 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 322 ms 27404 KB Output is correct
18 Correct 210 ms 27032 KB Output is correct
19 Correct 266 ms 28296 KB Output is correct
20 Correct 274 ms 28804 KB Output is correct
21 Correct 273 ms 28816 KB Output is correct
22 Correct 357 ms 27708 KB Output is correct
23 Correct 243 ms 28728 KB Output is correct
24 Correct 195 ms 22608 KB Output is correct
25 Correct 253 ms 26892 KB Output is correct
26 Correct 231 ms 26240 KB Output is correct
27 Correct 216 ms 27324 KB Output is correct
28 Correct 252 ms 27296 KB Output is correct
29 Correct 256 ms 29768 KB Output is correct
30 Correct 202 ms 29512 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 349 ms 29732 KB Output is correct
33 Correct 364 ms 32616 KB Output is correct
34 Correct 300 ms 32196 KB Output is correct
35 Correct 236 ms 29808 KB Output is correct
36 Correct 334 ms 33028 KB Output is correct
37 Correct 295 ms 33284 KB Output is correct
38 Correct 270 ms 32924 KB Output is correct
39 Correct 210 ms 32044 KB Output is correct
40 Correct 262 ms 27408 KB Output is correct
41 Correct 234 ms 29368 KB Output is correct
42 Correct 6 ms 9684 KB Output is correct
43 Correct 336 ms 27460 KB Output is correct
44 Correct 313 ms 32080 KB Output is correct
45 Correct 322 ms 30564 KB Output is correct
46 Correct 327 ms 35044 KB Output is correct
47 Correct 296 ms 31896 KB Output is correct
48 Correct 265 ms 31148 KB Output is correct
49 Correct 197 ms 31232 KB Output is correct
50 Correct 197 ms 21404 KB Output is correct
51 Correct 267 ms 32720 KB Output is correct
52 Correct 256 ms 28528 KB Output is correct
53 Correct 6 ms 9708 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 9 ms 9904 KB Output is correct
57 Correct 8 ms 9852 KB Output is correct
58 Correct 7 ms 9812 KB Output is correct
59 Correct 8 ms 9884 KB Output is correct
60 Correct 7 ms 9852 KB Output is correct
61 Correct 7 ms 9812 KB Output is correct
62 Correct 8 ms 9940 KB Output is correct
63 Correct 9 ms 9844 KB Output is correct
64 Correct 7 ms 9940 KB Output is correct
65 Correct 7 ms 9872 KB Output is correct
66 Correct 7 ms 9812 KB Output is correct
67 Correct 312 ms 31668 KB Output is correct
68 Correct 237 ms 30000 KB Output is correct
69 Correct 269 ms 32276 KB Output is correct
70 Correct 308 ms 32176 KB Output is correct
71 Correct 296 ms 30280 KB Output is correct
72 Correct 283 ms 30796 KB Output is correct
73 Correct 255 ms 31784 KB Output is correct
74 Correct 216 ms 24360 KB Output is correct
75 Correct 233 ms 29044 KB Output is correct
76 Correct 242 ms 28284 KB Output is correct
77 Correct 219 ms 29144 KB Output is correct
78 Correct 224 ms 29024 KB Output is correct
79 Correct 284 ms 32088 KB Output is correct
80 Correct 223 ms 33000 KB Output is correct
81 Correct 341 ms 32132 KB Output is correct
82 Correct 325 ms 32932 KB Output is correct
83 Correct 323 ms 28132 KB Output is correct
84 Correct 222 ms 29404 KB Output is correct
85 Correct 348 ms 34264 KB Output is correct
86 Correct 289 ms 34272 KB Output is correct
87 Correct 316 ms 33932 KB Output is correct
88 Correct 237 ms 26680 KB Output is correct
89 Correct 242 ms 26740 KB Output is correct
90 Correct 309 ms 29880 KB Output is correct
91 Correct 315 ms 32096 KB Output is correct
92 Correct 356 ms 33296 KB Output is correct
93 Correct 331 ms 34108 KB Output is correct
94 Correct 301 ms 31504 KB Output is correct
95 Correct 253 ms 30452 KB Output is correct
96 Correct 228 ms 30772 KB Output is correct
97 Correct 187 ms 21252 KB Output is correct
98 Correct 269 ms 33344 KB Output is correct
99 Correct 265 ms 29512 KB Output is correct
100 Correct 103 ms 13144 KB Output is correct
101 Correct 345 ms 32364 KB Output is correct
102 Correct 290 ms 27664 KB Output is correct
103 Correct 276 ms 24220 KB Output is correct
104 Correct 339 ms 27264 KB Output is correct