답안 #1084969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1084969 2024-09-07T09:24:03 Z dosts Stranded Far From Home (BOI22_island) C++17
100 / 100
369 ms 63936 KB
//Dost SEFEROĞLU
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<    
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
#define ordered_set tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
const int MOD = 1e9+7,inf = 2e18;
const int N = 2e5+50;
 
struct DSU {
    int n;
    vi dad,sz,sm;   
    vector<set<int>> stuff;
    DSU(int nn) {
        n = nn;
        dad.resize(n+1);
        iota(all(dad),0ll);
        sz.assign(n+1,1);
        sm.assign(n+1,1);
        stuff.resize(n+1);
    }
    int find(int x) {
        if (x == dad[x]) return x;
        return find(dad[x]);
    }
    void unite(int x,int y) {
        int a = find(x),b = find(y);
        if (a == b) return;
        if (sz[a] < sz[b]) swap(a,b);
        sz[a]+=sz[b];
        dad[b] = a;
        sm[a]+=sm[b];
        for (auto it : stuff[b]) stuff[a].insert(it);
        stuff[b].clear();
    }
    void deletecomp(int x) {
        stuff[find(x)].clear();
    }
};
 
void solve() {
    int n,m;
    cin >> n >> m;
    vi edges[n+1];
    map<int,vi> nds;
    vi w(n+1);
    DSU dsu(n);
    for (int i=1;i<=n;i++) {
        cin >> w[i];
        dsu.sm[i] = w[i];
        nds[w[i]].push_back(i);
    }
    for (int i=1;i<=m;i++) {
        int a,b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    for (int i=1;i<=n;i++) dsu.stuff[i].insert(i);
    for (auto& [v,nodes] : nds) {
        for (auto it : nodes) {
            for (auto itt : edges[it]) {
                if (dsu.sm[dsu.find(itt)] < w[it]) dsu.deletecomp(itt);
            }
        }
        for (auto it : nodes) {
            for (auto itt : edges[it]) {
                if (w[itt] <= w[it]) dsu.unite(it,itt);
            }
        }
    }
    for (int i=1;i<=n;i++) cout << dsu.stuff[dsu.find(i)].count(i);
    cout << endl;
}                    
                             
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 984 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 872 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 202 ms 63836 KB Output is correct
4 Correct 122 ms 42196 KB Output is correct
5 Correct 271 ms 61700 KB Output is correct
6 Correct 253 ms 58820 KB Output is correct
7 Correct 264 ms 63824 KB Output is correct
8 Correct 226 ms 43460 KB Output is correct
9 Correct 192 ms 60244 KB Output is correct
10 Correct 141 ms 58816 KB Output is correct
11 Correct 208 ms 43064 KB Output is correct
12 Correct 184 ms 42136 KB Output is correct
13 Correct 132 ms 40916 KB Output is correct
14 Correct 128 ms 41284 KB Output is correct
15 Correct 201 ms 63016 KB Output is correct
16 Correct 164 ms 61524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 366 ms 62464 KB Output is correct
3 Correct 340 ms 57968 KB Output is correct
4 Correct 136 ms 42696 KB Output is correct
5 Correct 116 ms 40904 KB Output is correct
6 Correct 350 ms 62900 KB Output is correct
7 Correct 197 ms 62800 KB Output is correct
8 Correct 192 ms 62924 KB Output is correct
9 Correct 172 ms 61520 KB Output is correct
10 Correct 164 ms 52168 KB Output is correct
11 Correct 144 ms 42036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 236 ms 43588 KB Output is correct
3 Correct 236 ms 43384 KB Output is correct
4 Correct 263 ms 43620 KB Output is correct
5 Correct 287 ms 44492 KB Output is correct
6 Correct 257 ms 41672 KB Output is correct
7 Correct 182 ms 44012 KB Output is correct
8 Correct 105 ms 43056 KB Output is correct
9 Correct 103 ms 24268 KB Output is correct
10 Correct 294 ms 45512 KB Output is correct
11 Correct 150 ms 41140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 984 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 872 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 772 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 452 KB Output is correct
17 Correct 202 ms 63836 KB Output is correct
18 Correct 122 ms 42196 KB Output is correct
19 Correct 271 ms 61700 KB Output is correct
20 Correct 253 ms 58820 KB Output is correct
21 Correct 264 ms 63824 KB Output is correct
22 Correct 226 ms 43460 KB Output is correct
23 Correct 192 ms 60244 KB Output is correct
24 Correct 141 ms 58816 KB Output is correct
25 Correct 208 ms 43064 KB Output is correct
26 Correct 184 ms 42136 KB Output is correct
27 Correct 132 ms 40916 KB Output is correct
28 Correct 128 ms 41284 KB Output is correct
29 Correct 201 ms 63016 KB Output is correct
30 Correct 164 ms 61524 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 366 ms 62464 KB Output is correct
33 Correct 340 ms 57968 KB Output is correct
34 Correct 136 ms 42696 KB Output is correct
35 Correct 116 ms 40904 KB Output is correct
36 Correct 350 ms 62900 KB Output is correct
37 Correct 197 ms 62800 KB Output is correct
38 Correct 192 ms 62924 KB Output is correct
39 Correct 172 ms 61520 KB Output is correct
40 Correct 164 ms 52168 KB Output is correct
41 Correct 144 ms 42036 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 236 ms 43588 KB Output is correct
44 Correct 236 ms 43384 KB Output is correct
45 Correct 263 ms 43620 KB Output is correct
46 Correct 287 ms 44492 KB Output is correct
47 Correct 257 ms 41672 KB Output is correct
48 Correct 182 ms 44012 KB Output is correct
49 Correct 105 ms 43056 KB Output is correct
50 Correct 103 ms 24268 KB Output is correct
51 Correct 294 ms 45512 KB Output is correct
52 Correct 150 ms 41140 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 2 ms 860 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 2 ms 860 KB Output is correct
60 Correct 1 ms 860 KB Output is correct
61 Correct 1 ms 860 KB Output is correct
62 Correct 2 ms 1028 KB Output is correct
63 Correct 2 ms 860 KB Output is correct
64 Correct 2 ms 860 KB Output is correct
65 Correct 1 ms 852 KB Output is correct
66 Correct 1 ms 860 KB Output is correct
67 Correct 175 ms 63936 KB Output is correct
68 Correct 120 ms 42308 KB Output is correct
69 Correct 284 ms 61732 KB Output is correct
70 Correct 258 ms 58884 KB Output is correct
71 Correct 285 ms 63824 KB Output is correct
72 Correct 245 ms 43560 KB Output is correct
73 Correct 188 ms 60240 KB Output is correct
74 Correct 140 ms 58820 KB Output is correct
75 Correct 208 ms 43080 KB Output is correct
76 Correct 163 ms 42200 KB Output is correct
77 Correct 121 ms 40904 KB Output is correct
78 Correct 139 ms 41304 KB Output is correct
79 Correct 189 ms 62992 KB Output is correct
80 Correct 175 ms 61520 KB Output is correct
81 Correct 360 ms 62544 KB Output is correct
82 Correct 331 ms 57940 KB Output is correct
83 Correct 145 ms 42592 KB Output is correct
84 Correct 118 ms 40908 KB Output is correct
85 Correct 369 ms 62964 KB Output is correct
86 Correct 203 ms 63056 KB Output is correct
87 Correct 195 ms 62804 KB Output is correct
88 Correct 178 ms 52160 KB Output is correct
89 Correct 158 ms 42036 KB Output is correct
90 Correct 232 ms 43588 KB Output is correct
91 Correct 228 ms 43388 KB Output is correct
92 Correct 263 ms 43704 KB Output is correct
93 Correct 282 ms 44492 KB Output is correct
94 Correct 237 ms 41836 KB Output is correct
95 Correct 166 ms 44192 KB Output is correct
96 Correct 108 ms 43080 KB Output is correct
97 Correct 102 ms 24268 KB Output is correct
98 Correct 303 ms 45752 KB Output is correct
99 Correct 138 ms 41088 KB Output is correct
100 Correct 33 ms 7512 KB Output is correct
101 Correct 346 ms 59316 KB Output is correct
102 Correct 185 ms 35708 KB Output is correct
103 Correct 268 ms 50652 KB Output is correct
104 Correct 351 ms 62800 KB Output is correct