Submission #938065

# Submission time Handle Problem Language Result Execution time Memory
938065 2024-03-04T19:06:31 Z LucaIlie Stranded Far From Home (BOI22_island) C++17
100 / 100
709 ms 103356 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2e5;
bool active[MAX_N + 1], sePoate[MAX_N + 1];
int s[MAX_N + 1];
vector<int> adj[MAX_N + 1];
map<long long, vector<int>> updates, queries;
priority_queue<long long> times;

struct DSU {
    int n;
    vector<int> sef, sz;
    vector<long long> sum;

    void init( int _n ) {
        n = _n;
        sef.resize( n );
        sz.resize( n );
        sum.resize( n );
        for ( int u = 0; u < n; u++ ) {
            sef[u] = u;
            sz[u] = 1;
            sum[u] = s[u];
        }
    }

    int findSef( int v ) {
        if ( sef[v] == v )
            return v;
        sef[v] = findSef( sef[v] );
        return sef[v];
    }

    int calcSz( int v ) {
        return sz[findSef( v )];
    }

    long long calcSum( int v ) {
        return sum[findSef( v )];
    }

    void unionn( int u, int v ) {
        u = findSef( u );
        v = findSef( v );
        if ( sz[u] > sz[v] )
            swap( u, v );

        if ( u == v )
            return;


        sef[u] = v;
        sz[v] += sz[u];
        sum[v] += sum[u];
    }
} orase;

int main() {
    int n, m;

    cin >> n >> m;
    for ( int v = 1; v <= n; v++ )
        cin >> s[v];
    for ( int i = 0; i < m; i++ ) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back( v );
        adj[v].push_back( u );
    }

    for ( int v = 1; v <= n; v++ ) {
        updates[s[v]].push_back( v );
        queries[s[v]].push_back( v );
        times.push( -s[v] );
    }

    orase.init( n + 1 );
    long long prvT = -1;
    while ( !times.empty() ){
        long long t = -times.top();
        times.pop();

        if ( t == prvT )
            continue;

        for ( int u: updates[t] ) {
            active[u] = true;
            for ( int v: adj[u] ) {
                if ( active[v] )
                    orase.unionn( u, v );
            }
        }

        for ( int v: queries[t] ) {
            int sz = orase.calcSz( v );
            long long sum = orase.calcSum( v );
            if ( sz == n )
                sePoate[v] = true;
            else if ( sum > t ) {
                queries[sum].push_back( v );
                times.push( -sum );
            }
        }
        
        prvT = t;
    }

    for ( int v = 1; v <= n; v++ )
        cout << sePoate[v];

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 5 ms 5724 KB Output is correct
5 Correct 4 ms 5724 KB Output is correct
6 Correct 3 ms 5176 KB Output is correct
7 Correct 4 ms 5732 KB Output is correct
8 Correct 4 ms 5724 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 5 ms 5724 KB Output is correct
11 Correct 5 ms 5980 KB Output is correct
12 Correct 4 ms 5720 KB Output is correct
13 Correct 3 ms 5232 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 463 ms 86980 KB Output is correct
4 Correct 173 ms 26292 KB Output is correct
5 Correct 487 ms 86464 KB Output is correct
6 Correct 446 ms 78524 KB Output is correct
7 Correct 518 ms 89384 KB Output is correct
8 Correct 258 ms 27328 KB Output is correct
9 Correct 357 ms 73180 KB Output is correct
10 Correct 273 ms 55192 KB Output is correct
11 Correct 163 ms 23052 KB Output is correct
12 Correct 205 ms 25960 KB Output is correct
13 Correct 192 ms 25600 KB Output is correct
14 Correct 172 ms 25792 KB Output is correct
15 Correct 458 ms 103188 KB Output is correct
16 Correct 432 ms 101564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 700 ms 85764 KB Output is correct
3 Correct 644 ms 80572 KB Output is correct
4 Correct 192 ms 23340 KB Output is correct
5 Correct 169 ms 25128 KB Output is correct
6 Correct 686 ms 90956 KB Output is correct
7 Correct 482 ms 103356 KB Output is correct
8 Correct 460 ms 103320 KB Output is correct
9 Correct 436 ms 101432 KB Output is correct
10 Correct 280 ms 44608 KB Output is correct
11 Correct 209 ms 26500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 243 ms 23144 KB Output is correct
3 Correct 256 ms 27756 KB Output is correct
4 Correct 252 ms 27608 KB Output is correct
5 Correct 198 ms 23340 KB Output is correct
6 Correct 193 ms 22572 KB Output is correct
7 Correct 203 ms 28300 KB Output is correct
8 Correct 170 ms 26160 KB Output is correct
9 Correct 151 ms 16940 KB Output is correct
10 Correct 176 ms 26052 KB Output is correct
11 Correct 204 ms 23996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 5 ms 5724 KB Output is correct
5 Correct 4 ms 5724 KB Output is correct
6 Correct 3 ms 5176 KB Output is correct
7 Correct 4 ms 5732 KB Output is correct
8 Correct 4 ms 5724 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 5 ms 5724 KB Output is correct
11 Correct 5 ms 5980 KB Output is correct
12 Correct 4 ms 5720 KB Output is correct
13 Correct 3 ms 5232 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 463 ms 86980 KB Output is correct
18 Correct 173 ms 26292 KB Output is correct
19 Correct 487 ms 86464 KB Output is correct
20 Correct 446 ms 78524 KB Output is correct
21 Correct 518 ms 89384 KB Output is correct
22 Correct 258 ms 27328 KB Output is correct
23 Correct 357 ms 73180 KB Output is correct
24 Correct 273 ms 55192 KB Output is correct
25 Correct 163 ms 23052 KB Output is correct
26 Correct 205 ms 25960 KB Output is correct
27 Correct 192 ms 25600 KB Output is correct
28 Correct 172 ms 25792 KB Output is correct
29 Correct 458 ms 103188 KB Output is correct
30 Correct 432 ms 101564 KB Output is correct
31 Correct 1 ms 4956 KB Output is correct
32 Correct 700 ms 85764 KB Output is correct
33 Correct 644 ms 80572 KB Output is correct
34 Correct 192 ms 23340 KB Output is correct
35 Correct 169 ms 25128 KB Output is correct
36 Correct 686 ms 90956 KB Output is correct
37 Correct 482 ms 103356 KB Output is correct
38 Correct 460 ms 103320 KB Output is correct
39 Correct 436 ms 101432 KB Output is correct
40 Correct 280 ms 44608 KB Output is correct
41 Correct 209 ms 26500 KB Output is correct
42 Correct 1 ms 4952 KB Output is correct
43 Correct 243 ms 23144 KB Output is correct
44 Correct 256 ms 27756 KB Output is correct
45 Correct 252 ms 27608 KB Output is correct
46 Correct 198 ms 23340 KB Output is correct
47 Correct 193 ms 22572 KB Output is correct
48 Correct 203 ms 28300 KB Output is correct
49 Correct 170 ms 26160 KB Output is correct
50 Correct 151 ms 16940 KB Output is correct
51 Correct 176 ms 26052 KB Output is correct
52 Correct 204 ms 23996 KB Output is correct
53 Correct 1 ms 4956 KB Output is correct
54 Correct 1 ms 4956 KB Output is correct
55 Correct 1 ms 4952 KB Output is correct
56 Correct 4 ms 5724 KB Output is correct
57 Correct 4 ms 5720 KB Output is correct
58 Correct 3 ms 5212 KB Output is correct
59 Correct 4 ms 5724 KB Output is correct
60 Correct 4 ms 5724 KB Output is correct
61 Correct 3 ms 5212 KB Output is correct
62 Correct 5 ms 5684 KB Output is correct
63 Correct 5 ms 5980 KB Output is correct
64 Correct 4 ms 5724 KB Output is correct
65 Correct 3 ms 5212 KB Output is correct
66 Correct 3 ms 5212 KB Output is correct
67 Correct 473 ms 91496 KB Output is correct
68 Correct 187 ms 25280 KB Output is correct
69 Correct 497 ms 87096 KB Output is correct
70 Correct 441 ms 78628 KB Output is correct
71 Correct 507 ms 89376 KB Output is correct
72 Correct 214 ms 26860 KB Output is correct
73 Correct 350 ms 73404 KB Output is correct
74 Correct 255 ms 54976 KB Output is correct
75 Correct 161 ms 23036 KB Output is correct
76 Correct 195 ms 25668 KB Output is correct
77 Correct 174 ms 26592 KB Output is correct
78 Correct 196 ms 26504 KB Output is correct
79 Correct 466 ms 103168 KB Output is correct
80 Correct 443 ms 101836 KB Output is correct
81 Correct 703 ms 90260 KB Output is correct
82 Correct 626 ms 80320 KB Output is correct
83 Correct 192 ms 23464 KB Output is correct
84 Correct 170 ms 25644 KB Output is correct
85 Correct 709 ms 90748 KB Output is correct
86 Correct 484 ms 103356 KB Output is correct
87 Correct 464 ms 103176 KB Output is correct
88 Correct 289 ms 45064 KB Output is correct
89 Correct 212 ms 26420 KB Output is correct
90 Correct 252 ms 27436 KB Output is correct
91 Correct 268 ms 27888 KB Output is correct
92 Correct 251 ms 27840 KB Output is correct
93 Correct 199 ms 23336 KB Output is correct
94 Correct 203 ms 22704 KB Output is correct
95 Correct 196 ms 28956 KB Output is correct
96 Correct 170 ms 25396 KB Output is correct
97 Correct 158 ms 16584 KB Output is correct
98 Correct 176 ms 26560 KB Output is correct
99 Correct 196 ms 24000 KB Output is correct
100 Correct 79 ms 10324 KB Output is correct
101 Correct 628 ms 79040 KB Output is correct
102 Correct 187 ms 20020 KB Output is correct
103 Correct 494 ms 65728 KB Output is correct
104 Correct 695 ms 88108 KB Output is correct