답안 #644530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644530 2022-09-24T20:30:46 Z Tudy006 Stranded Far From Home (BOI22_island) C++14
100 / 100
387 ms 41456 KB
#include <bits/stdc++.h>

using namespace std;

const int NMAX = 2e5;

pair <int, int> v[NMAX + 1];
int father[NMAX + 1];
bool viz[NMAX + 1];
vector <int> edges[NMAX + 1];
vector <int> children[NMAX + 1];

struct DSU {
    int father[NMAX + 1];
    void init() {
        for ( int i = 1; i <= NMAX; i ++ ) father[i] = i;
    }
    int root( int x ) {
        if ( father[x] == x ) return x;
        return ( father[x] = root( father[x] ) );
    }
    bool arejoined( int x, int y ) {
        return root( x ) == root( y );
    }
    void join( int x, int y ) {
        x = root( x );
        y = root( y );
        father[x] = y;
    }
};

long long sum[NMAX + 1];
bool can[NMAX + 1];
long long dfs_sum( int node ) {
    sum[node] = v[node].first;
    for ( auto it : children[node] ) {
        sum[node] += dfs_sum( it );
    }
    return sum[node];
}
void dfs_can( int node ) {
    if ( sum[node] >= v[father[node]].first && can[father[node]] == 1 ) can[node] = 1;
    for ( auto it : children[node] ) dfs_can( it );
}
bool cmp( pair <int, int> a, pair <int, int> b ) {
    return a.second < b.second;
}
int main() {
    int n, m, a, b;
    cin >> n >> m;
    for ( int i = 1; i <= n; i ++ ) {
        cin >> v[i].first;
        sum[i] = v[i].first;
        v[i].second = i;
    }
    for ( int i = 1; i <= m; i ++ ) {
        cin >> a >> b;
        edges[a].push_back( b );
        edges[b].push_back( a );
    }
    sort( v + 1, v + n + 1 );
    DSU dsu;
    dsu.init();
    for ( int i = 1; i <= n; i ++ ) {
        int node = v[i].second;
        viz[node] = true;
        for ( auto it : edges[node] ) {
            if ( viz[it] && !dsu.arejoined( node, it ) ) {
                father[dsu.root( it )] = node;
                children[node].push_back( dsu.root( it ) );
                dsu.join( dsu.root( it ), node );
            }
        }
    }
    int aux = v[n].second;
    sort( v + 1, v + n + 1, cmp );
    can[0] = 1;
    dfs_sum( aux );
    dfs_can( aux );
    for ( int i = 1; i <= n; i ++ ) cout << can[i];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10452 KB Output is correct
2 Correct 5 ms 10452 KB Output is correct
3 Correct 5 ms 10412 KB Output is correct
4 Correct 7 ms 10580 KB Output is correct
5 Correct 8 ms 10624 KB Output is correct
6 Correct 8 ms 10580 KB Output is correct
7 Correct 8 ms 10596 KB Output is correct
8 Correct 7 ms 10580 KB Output is correct
9 Correct 8 ms 10796 KB Output is correct
10 Correct 7 ms 10580 KB Output is correct
11 Correct 8 ms 10580 KB Output is correct
12 Correct 7 ms 10624 KB Output is correct
13 Correct 7 ms 10760 KB Output is correct
14 Correct 7 ms 10632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10452 KB Output is correct
2 Correct 5 ms 10452 KB Output is correct
3 Correct 273 ms 29176 KB Output is correct
4 Correct 248 ms 38852 KB Output is correct
5 Correct 298 ms 28980 KB Output is correct
6 Correct 307 ms 29488 KB Output is correct
7 Correct 301 ms 29564 KB Output is correct
8 Correct 318 ms 41260 KB Output is correct
9 Correct 263 ms 28576 KB Output is correct
10 Correct 215 ms 26684 KB Output is correct
11 Correct 258 ms 40996 KB Output is correct
12 Correct 311 ms 30652 KB Output is correct
13 Correct 263 ms 39528 KB Output is correct
14 Correct 248 ms 38732 KB Output is correct
15 Correct 264 ms 41204 KB Output is correct
16 Correct 205 ms 40336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10452 KB Output is correct
2 Correct 325 ms 25228 KB Output is correct
3 Correct 353 ms 29728 KB Output is correct
4 Correct 310 ms 41312 KB Output is correct
5 Correct 259 ms 36820 KB Output is correct
6 Correct 335 ms 29804 KB Output is correct
7 Correct 291 ms 41276 KB Output is correct
8 Correct 296 ms 41256 KB Output is correct
9 Correct 212 ms 40236 KB Output is correct
10 Correct 284 ms 33032 KB Output is correct
11 Correct 262 ms 29924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10452 KB Output is correct
2 Correct 365 ms 25688 KB Output is correct
3 Correct 349 ms 29684 KB Output is correct
4 Correct 363 ms 29820 KB Output is correct
5 Correct 351 ms 29772 KB Output is correct
6 Correct 299 ms 30056 KB Output is correct
7 Correct 257 ms 35292 KB Output is correct
8 Correct 201 ms 40008 KB Output is correct
9 Correct 203 ms 22172 KB Output is correct
10 Correct 307 ms 27916 KB Output is correct
11 Correct 249 ms 29964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10452 KB Output is correct
2 Correct 5 ms 10452 KB Output is correct
3 Correct 5 ms 10412 KB Output is correct
4 Correct 7 ms 10580 KB Output is correct
5 Correct 8 ms 10624 KB Output is correct
6 Correct 8 ms 10580 KB Output is correct
7 Correct 8 ms 10596 KB Output is correct
8 Correct 7 ms 10580 KB Output is correct
9 Correct 8 ms 10796 KB Output is correct
10 Correct 7 ms 10580 KB Output is correct
11 Correct 8 ms 10580 KB Output is correct
12 Correct 7 ms 10624 KB Output is correct
13 Correct 7 ms 10760 KB Output is correct
14 Correct 7 ms 10632 KB Output is correct
15 Correct 5 ms 10452 KB Output is correct
16 Correct 5 ms 10452 KB Output is correct
17 Correct 273 ms 29176 KB Output is correct
18 Correct 248 ms 38852 KB Output is correct
19 Correct 298 ms 28980 KB Output is correct
20 Correct 307 ms 29488 KB Output is correct
21 Correct 301 ms 29564 KB Output is correct
22 Correct 318 ms 41260 KB Output is correct
23 Correct 263 ms 28576 KB Output is correct
24 Correct 215 ms 26684 KB Output is correct
25 Correct 258 ms 40996 KB Output is correct
26 Correct 311 ms 30652 KB Output is correct
27 Correct 263 ms 39528 KB Output is correct
28 Correct 248 ms 38732 KB Output is correct
29 Correct 264 ms 41204 KB Output is correct
30 Correct 205 ms 40336 KB Output is correct
31 Correct 5 ms 10452 KB Output is correct
32 Correct 325 ms 25228 KB Output is correct
33 Correct 353 ms 29728 KB Output is correct
34 Correct 310 ms 41312 KB Output is correct
35 Correct 259 ms 36820 KB Output is correct
36 Correct 335 ms 29804 KB Output is correct
37 Correct 291 ms 41276 KB Output is correct
38 Correct 296 ms 41256 KB Output is correct
39 Correct 212 ms 40236 KB Output is correct
40 Correct 284 ms 33032 KB Output is correct
41 Correct 262 ms 29924 KB Output is correct
42 Correct 5 ms 10452 KB Output is correct
43 Correct 365 ms 25688 KB Output is correct
44 Correct 349 ms 29684 KB Output is correct
45 Correct 363 ms 29820 KB Output is correct
46 Correct 351 ms 29772 KB Output is correct
47 Correct 299 ms 30056 KB Output is correct
48 Correct 257 ms 35292 KB Output is correct
49 Correct 201 ms 40008 KB Output is correct
50 Correct 203 ms 22172 KB Output is correct
51 Correct 307 ms 27916 KB Output is correct
52 Correct 249 ms 29964 KB Output is correct
53 Correct 6 ms 10452 KB Output is correct
54 Correct 6 ms 10452 KB Output is correct
55 Correct 6 ms 10452 KB Output is correct
56 Correct 10 ms 10636 KB Output is correct
57 Correct 8 ms 10636 KB Output is correct
58 Correct 7 ms 10604 KB Output is correct
59 Correct 7 ms 10632 KB Output is correct
60 Correct 7 ms 10544 KB Output is correct
61 Correct 8 ms 10760 KB Output is correct
62 Correct 8 ms 10580 KB Output is correct
63 Correct 8 ms 10688 KB Output is correct
64 Correct 7 ms 10676 KB Output is correct
65 Correct 9 ms 10728 KB Output is correct
66 Correct 7 ms 10580 KB Output is correct
67 Correct 279 ms 33852 KB Output is correct
68 Correct 252 ms 38764 KB Output is correct
69 Correct 292 ms 29012 KB Output is correct
70 Correct 310 ms 29460 KB Output is correct
71 Correct 325 ms 29532 KB Output is correct
72 Correct 319 ms 41276 KB Output is correct
73 Correct 260 ms 28580 KB Output is correct
74 Correct 220 ms 26676 KB Output is correct
75 Correct 270 ms 40968 KB Output is correct
76 Correct 307 ms 30688 KB Output is correct
77 Correct 259 ms 39616 KB Output is correct
78 Correct 251 ms 38800 KB Output is correct
79 Correct 268 ms 41272 KB Output is correct
80 Correct 205 ms 40260 KB Output is correct
81 Correct 322 ms 29636 KB Output is correct
82 Correct 347 ms 29804 KB Output is correct
83 Correct 304 ms 41224 KB Output is correct
84 Correct 242 ms 36684 KB Output is correct
85 Correct 330 ms 29720 KB Output is correct
86 Correct 289 ms 41308 KB Output is correct
87 Correct 289 ms 41456 KB Output is correct
88 Correct 271 ms 32724 KB Output is correct
89 Correct 256 ms 30012 KB Output is correct
90 Correct 344 ms 30156 KB Output is correct
91 Correct 353 ms 29740 KB Output is correct
92 Correct 351 ms 29660 KB Output is correct
93 Correct 347 ms 29732 KB Output is correct
94 Correct 303 ms 30180 KB Output is correct
95 Correct 257 ms 35388 KB Output is correct
96 Correct 207 ms 40012 KB Output is correct
97 Correct 194 ms 22248 KB Output is correct
98 Correct 288 ms 27892 KB Output is correct
99 Correct 262 ms 30016 KB Output is correct
100 Correct 106 ms 14888 KB Output is correct
101 Correct 387 ms 29656 KB Output is correct
102 Correct 294 ms 29004 KB Output is correct
103 Correct 312 ms 29648 KB Output is correct
104 Correct 369 ms 30288 KB Output is correct