답안 #573386

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573386 2022-06-06T13:45:23 Z MohamedFaresNebili Stranded Far From Home (BOI22_island) C++14
100 / 100
306 ms 48380 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

        using namespace std;
        using namespace __gnu_pbds;

        using ll = long long;
        using ii = pair<int, int>;
        using vi = vector<int>;

        #define pb push_back
        #define pp pop_back
        #define ff first
        #define ss second
        #define lb lower_bound
        #define int ll

        typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;

        int N, M, S[200001], par[200001], anc[200001];
        vector<int> adj[200001], sub[200001], D[200001];
        int res[200001]; bool vis[200001], processed[200001];

        int findSet(int v) {
            if(par[v] == v) return v;
            return par[v] = findSet(par[v]);
        }
        void unionSet(int u, int v) {
            u = findSet(u), v = findSet(v);
            if(u == v) return;
            par[v] = u; S[u] += S[v];
        }
        void dfs(int v, bool state) {
            res[v] &= state;
            for(auto u : D[v]) {
                dfs(u, res[v]);
            }
        }

        int32_t main() {
            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            cin >> N >> M; vector<ii> E;
            for(int l = 1; l <= N; l++) {
                cin >> S[l]; E.pb({S[l], l});
                par[l] = l; sub[l].pb(l); res[l] = 1;
            }
            sort(E.begin(), E.end());
            for(int l = 0; l < M; l++) {
                int U, V; cin >> U >> V;
                adj[U].pb(V), adj[V].pb(U);
            }
            for(auto e : E) {
                int U = e.ss;
                for(auto v : adj[U]) {
                    if(!processed[v]) continue;
                    int V = findSet(v);
                    if(S[V] < S[U]) res[anc[V]] = 0;
                    V = anc[V];
                    if(!vis[V]) {
                        vis[V] = 1; D[U].pb(V);
                    }
                }
                for(auto v : adj[U]) {
                    if(!processed[v]) continue;
                    int V = findSet(v);
                    V = anc[V]; vis[V] = 0;
                }
                for(auto V : adj[U]) {
                    if(!processed[V]) continue;
                    unionSet(U, V);
                }
                int V = findSet(U); anc[V] = U;
                processed[U] = 1;
            }
            dfs(E[N - 1].ss, 1);
            for(int l = 1; l <= N; l++)
                cout << res[l];
        }


























# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 9 ms 14676 KB Output is correct
5 Correct 9 ms 14704 KB Output is correct
6 Correct 9 ms 14548 KB Output is correct
7 Correct 9 ms 14684 KB Output is correct
8 Correct 8 ms 14648 KB Output is correct
9 Correct 8 ms 14784 KB Output is correct
10 Correct 8 ms 14676 KB Output is correct
11 Correct 8 ms 14676 KB Output is correct
12 Correct 8 ms 14676 KB Output is correct
13 Correct 8 ms 14668 KB Output is correct
14 Correct 9 ms 14648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14420 KB Output is correct
2 Correct 9 ms 14420 KB Output is correct
3 Correct 158 ms 42724 KB Output is correct
4 Correct 152 ms 47128 KB Output is correct
5 Correct 214 ms 39608 KB Output is correct
6 Correct 197 ms 40512 KB Output is correct
7 Correct 190 ms 40472 KB Output is correct
8 Correct 195 ms 47692 KB Output is correct
9 Correct 172 ms 40072 KB Output is correct
10 Correct 134 ms 39760 KB Output is correct
11 Correct 160 ms 48372 KB Output is correct
12 Correct 217 ms 42532 KB Output is correct
13 Correct 159 ms 46772 KB Output is correct
14 Correct 167 ms 46196 KB Output is correct
15 Correct 173 ms 46788 KB Output is correct
16 Correct 108 ms 46404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 254 ms 39304 KB Output is correct
3 Correct 228 ms 39512 KB Output is correct
4 Correct 186 ms 46716 KB Output is correct
5 Correct 164 ms 45116 KB Output is correct
6 Correct 226 ms 39488 KB Output is correct
7 Correct 198 ms 46808 KB Output is correct
8 Correct 180 ms 46756 KB Output is correct
9 Correct 105 ms 46488 KB Output is correct
10 Correct 161 ms 40980 KB Output is correct
11 Correct 205 ms 40472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 241 ms 40724 KB Output is correct
3 Correct 296 ms 40432 KB Output is correct
4 Correct 258 ms 40516 KB Output is correct
5 Correct 224 ms 40524 KB Output is correct
6 Correct 222 ms 40036 KB Output is correct
7 Correct 135 ms 43952 KB Output is correct
8 Correct 110 ms 48380 KB Output is correct
9 Correct 186 ms 30180 KB Output is correct
10 Correct 186 ms 40472 KB Output is correct
11 Correct 166 ms 40600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 9 ms 14676 KB Output is correct
5 Correct 9 ms 14704 KB Output is correct
6 Correct 9 ms 14548 KB Output is correct
7 Correct 9 ms 14684 KB Output is correct
8 Correct 8 ms 14648 KB Output is correct
9 Correct 8 ms 14784 KB Output is correct
10 Correct 8 ms 14676 KB Output is correct
11 Correct 8 ms 14676 KB Output is correct
12 Correct 8 ms 14676 KB Output is correct
13 Correct 8 ms 14668 KB Output is correct
14 Correct 9 ms 14648 KB Output is correct
15 Correct 11 ms 14420 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 158 ms 42724 KB Output is correct
18 Correct 152 ms 47128 KB Output is correct
19 Correct 214 ms 39608 KB Output is correct
20 Correct 197 ms 40512 KB Output is correct
21 Correct 190 ms 40472 KB Output is correct
22 Correct 195 ms 47692 KB Output is correct
23 Correct 172 ms 40072 KB Output is correct
24 Correct 134 ms 39760 KB Output is correct
25 Correct 160 ms 48372 KB Output is correct
26 Correct 217 ms 42532 KB Output is correct
27 Correct 159 ms 46772 KB Output is correct
28 Correct 167 ms 46196 KB Output is correct
29 Correct 173 ms 46788 KB Output is correct
30 Correct 108 ms 46404 KB Output is correct
31 Correct 8 ms 14420 KB Output is correct
32 Correct 254 ms 39304 KB Output is correct
33 Correct 228 ms 39512 KB Output is correct
34 Correct 186 ms 46716 KB Output is correct
35 Correct 164 ms 45116 KB Output is correct
36 Correct 226 ms 39488 KB Output is correct
37 Correct 198 ms 46808 KB Output is correct
38 Correct 180 ms 46756 KB Output is correct
39 Correct 105 ms 46488 KB Output is correct
40 Correct 161 ms 40980 KB Output is correct
41 Correct 205 ms 40472 KB Output is correct
42 Correct 7 ms 14420 KB Output is correct
43 Correct 241 ms 40724 KB Output is correct
44 Correct 296 ms 40432 KB Output is correct
45 Correct 258 ms 40516 KB Output is correct
46 Correct 224 ms 40524 KB Output is correct
47 Correct 222 ms 40036 KB Output is correct
48 Correct 135 ms 43952 KB Output is correct
49 Correct 110 ms 48380 KB Output is correct
50 Correct 186 ms 30180 KB Output is correct
51 Correct 186 ms 40472 KB Output is correct
52 Correct 166 ms 40600 KB Output is correct
53 Correct 8 ms 14420 KB Output is correct
54 Correct 11 ms 14416 KB Output is correct
55 Correct 9 ms 14400 KB Output is correct
56 Correct 11 ms 14676 KB Output is correct
57 Correct 12 ms 14676 KB Output is correct
58 Correct 8 ms 14548 KB Output is correct
59 Correct 9 ms 14632 KB Output is correct
60 Correct 9 ms 14548 KB Output is correct
61 Correct 9 ms 14676 KB Output is correct
62 Correct 11 ms 14676 KB Output is correct
63 Correct 9 ms 14676 KB Output is correct
64 Correct 11 ms 14676 KB Output is correct
65 Correct 11 ms 14716 KB Output is correct
66 Correct 9 ms 14676 KB Output is correct
67 Correct 157 ms 42656 KB Output is correct
68 Correct 168 ms 47068 KB Output is correct
69 Correct 189 ms 39672 KB Output is correct
70 Correct 192 ms 40420 KB Output is correct
71 Correct 239 ms 40428 KB Output is correct
72 Correct 208 ms 47688 KB Output is correct
73 Correct 166 ms 40092 KB Output is correct
74 Correct 156 ms 39684 KB Output is correct
75 Correct 159 ms 48308 KB Output is correct
76 Correct 214 ms 42536 KB Output is correct
77 Correct 163 ms 46776 KB Output is correct
78 Correct 166 ms 46280 KB Output is correct
79 Correct 155 ms 46800 KB Output is correct
80 Correct 143 ms 46424 KB Output is correct
81 Correct 212 ms 39300 KB Output is correct
82 Correct 229 ms 39508 KB Output is correct
83 Correct 179 ms 46796 KB Output is correct
84 Correct 141 ms 45032 KB Output is correct
85 Correct 222 ms 39484 KB Output is correct
86 Correct 193 ms 46732 KB Output is correct
87 Correct 160 ms 46760 KB Output is correct
88 Correct 150 ms 41088 KB Output is correct
89 Correct 170 ms 40484 KB Output is correct
90 Correct 262 ms 40672 KB Output is correct
91 Correct 252 ms 40560 KB Output is correct
92 Correct 284 ms 40532 KB Output is correct
93 Correct 214 ms 40504 KB Output is correct
94 Correct 211 ms 40124 KB Output is correct
95 Correct 148 ms 43940 KB Output is correct
96 Correct 111 ms 48380 KB Output is correct
97 Correct 145 ms 30104 KB Output is correct
98 Correct 222 ms 40476 KB Output is correct
99 Correct 169 ms 40444 KB Output is correct
100 Correct 51 ms 19276 KB Output is correct
101 Correct 306 ms 40500 KB Output is correct
102 Correct 198 ms 37116 KB Output is correct
103 Correct 259 ms 38352 KB Output is correct
104 Correct 283 ms 40644 KB Output is correct