답안 #850447

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850447 2023-09-16T14:54:57 Z Ahmed57 Stranded Far From Home (BOI22_island) C++17
100 / 100
281 ms 38196 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int pr[200001],gs[200001],val[200001];
vector<int> adj[200001],ne[200001];
int find(int x){
    if(x==pr[x])return x;
    return pr[x] = find(pr[x]);
}
bool mergegroup(int a,int b){
    a=find(a),b=find(b);
    if(a==b)return 0;
    pr[a]=b,gs[b]+=gs[a];
    return 1;
}
signed main(){
    int n,m;
    cin>>n>>m;
    int arr[n];
    vector<pair<int,int>> v;
    for(int i = 0;i<n;i++){
        cin>>arr[i];val[i] = 1;
        pr[i] = i;gs[i] = arr[i];
        v.push_back({arr[i],i});
    }
    sort(v.begin(),v.end());
    for(int i = 0;i<m;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        if(a>b)swap(a,b);
        if(arr[a]>arr[b])adj[a].push_back(b);
        else if(arr[b]>arr[a])adj[b].push_back(a);
        else adj[b].push_back(a);
    }for(auto i:v){
        int co = i.first , x = i.second;
        for(auto j:adj[x]){
            int lol = find(j) , xd = gs[lol];
            if(mergegroup(lol,x)){
                ne[x].push_back(lol);
                if(xd<co){
                    queue<int> q;q.push(lol);
                    val[lol] = 0;
                    while(!q.empty()){
                        int xx = q.front();q.pop();
                        for(auto j:ne[xx]){
                            if(val[j]){
                                val[j] = 0;
                                q.push(j);
                            }
                        }
                    }
                }
            }
        }
    }
    for(int i = 0;i<n;i++)cout<<val[i];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 4 ms 12892 KB Output is correct
5 Correct 4 ms 12892 KB Output is correct
6 Correct 4 ms 12892 KB Output is correct
7 Correct 4 ms 12892 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 4 ms 12892 KB Output is correct
10 Correct 4 ms 12892 KB Output is correct
11 Correct 4 ms 12980 KB Output is correct
12 Correct 4 ms 12892 KB Output is correct
13 Correct 4 ms 12892 KB Output is correct
14 Correct 4 ms 13024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 205 ms 28248 KB Output is correct
4 Correct 199 ms 37040 KB Output is correct
5 Correct 211 ms 31572 KB Output is correct
6 Correct 243 ms 32928 KB Output is correct
7 Correct 204 ms 32044 KB Output is correct
8 Correct 205 ms 36124 KB Output is correct
9 Correct 195 ms 30144 KB Output is correct
10 Correct 160 ms 29112 KB Output is correct
11 Correct 192 ms 36024 KB Output is correct
12 Correct 201 ms 33936 KB Output is correct
13 Correct 178 ms 38196 KB Output is correct
14 Correct 165 ms 37280 KB Output is correct
15 Correct 214 ms 36248 KB Output is correct
16 Correct 152 ms 35256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 220 ms 27664 KB Output is correct
3 Correct 255 ms 32448 KB Output is correct
4 Correct 214 ms 36280 KB Output is correct
5 Correct 159 ms 35516 KB Output is correct
6 Correct 234 ms 32748 KB Output is correct
7 Correct 211 ms 36316 KB Output is correct
8 Correct 211 ms 36244 KB Output is correct
9 Correct 156 ms 35388 KB Output is correct
10 Correct 203 ms 31412 KB Output is correct
11 Correct 203 ms 31400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 238 ms 27648 KB Output is correct
3 Correct 256 ms 33140 KB Output is correct
4 Correct 245 ms 32668 KB Output is correct
5 Correct 218 ms 32668 KB Output is correct
6 Correct 198 ms 32140 KB Output is correct
7 Correct 180 ms 32000 KB Output is correct
8 Correct 163 ms 36788 KB Output is correct
9 Correct 137 ms 24688 KB Output is correct
10 Correct 168 ms 30732 KB Output is correct
11 Correct 195 ms 31328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 4 ms 12892 KB Output is correct
5 Correct 4 ms 12892 KB Output is correct
6 Correct 4 ms 12892 KB Output is correct
7 Correct 4 ms 12892 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 4 ms 12892 KB Output is correct
10 Correct 4 ms 12892 KB Output is correct
11 Correct 4 ms 12980 KB Output is correct
12 Correct 4 ms 12892 KB Output is correct
13 Correct 4 ms 12892 KB Output is correct
14 Correct 4 ms 13024 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 205 ms 28248 KB Output is correct
18 Correct 199 ms 37040 KB Output is correct
19 Correct 211 ms 31572 KB Output is correct
20 Correct 243 ms 32928 KB Output is correct
21 Correct 204 ms 32044 KB Output is correct
22 Correct 205 ms 36124 KB Output is correct
23 Correct 195 ms 30144 KB Output is correct
24 Correct 160 ms 29112 KB Output is correct
25 Correct 192 ms 36024 KB Output is correct
26 Correct 201 ms 33936 KB Output is correct
27 Correct 178 ms 38196 KB Output is correct
28 Correct 165 ms 37280 KB Output is correct
29 Correct 214 ms 36248 KB Output is correct
30 Correct 152 ms 35256 KB Output is correct
31 Correct 3 ms 12888 KB Output is correct
32 Correct 220 ms 27664 KB Output is correct
33 Correct 255 ms 32448 KB Output is correct
34 Correct 214 ms 36280 KB Output is correct
35 Correct 159 ms 35516 KB Output is correct
36 Correct 234 ms 32748 KB Output is correct
37 Correct 211 ms 36316 KB Output is correct
38 Correct 211 ms 36244 KB Output is correct
39 Correct 156 ms 35388 KB Output is correct
40 Correct 203 ms 31412 KB Output is correct
41 Correct 203 ms 31400 KB Output is correct
42 Correct 2 ms 12892 KB Output is correct
43 Correct 238 ms 27648 KB Output is correct
44 Correct 256 ms 33140 KB Output is correct
45 Correct 245 ms 32668 KB Output is correct
46 Correct 218 ms 32668 KB Output is correct
47 Correct 198 ms 32140 KB Output is correct
48 Correct 180 ms 32000 KB Output is correct
49 Correct 163 ms 36788 KB Output is correct
50 Correct 137 ms 24688 KB Output is correct
51 Correct 168 ms 30732 KB Output is correct
52 Correct 195 ms 31328 KB Output is correct
53 Correct 2 ms 12892 KB Output is correct
54 Correct 3 ms 12892 KB Output is correct
55 Correct 2 ms 12892 KB Output is correct
56 Correct 4 ms 12936 KB Output is correct
57 Correct 4 ms 12892 KB Output is correct
58 Correct 4 ms 12892 KB Output is correct
59 Correct 4 ms 12892 KB Output is correct
60 Correct 4 ms 12892 KB Output is correct
61 Correct 4 ms 13148 KB Output is correct
62 Correct 4 ms 12892 KB Output is correct
63 Correct 5 ms 12892 KB Output is correct
64 Correct 4 ms 12892 KB Output is correct
65 Correct 4 ms 12972 KB Output is correct
66 Correct 4 ms 12936 KB Output is correct
67 Correct 204 ms 32988 KB Output is correct
68 Correct 186 ms 35952 KB Output is correct
69 Correct 199 ms 31500 KB Output is correct
70 Correct 192 ms 32360 KB Output is correct
71 Correct 207 ms 32056 KB Output is correct
72 Correct 203 ms 36152 KB Output is correct
73 Correct 178 ms 30220 KB Output is correct
74 Correct 192 ms 29460 KB Output is correct
75 Correct 192 ms 36080 KB Output is correct
76 Correct 187 ms 33720 KB Output is correct
77 Correct 159 ms 37592 KB Output is correct
78 Correct 166 ms 37284 KB Output is correct
79 Correct 191 ms 36268 KB Output is correct
80 Correct 164 ms 35400 KB Output is correct
81 Correct 217 ms 31912 KB Output is correct
82 Correct 225 ms 32184 KB Output is correct
83 Correct 208 ms 36272 KB Output is correct
84 Correct 156 ms 35576 KB Output is correct
85 Correct 233 ms 32432 KB Output is correct
86 Correct 211 ms 36404 KB Output is correct
87 Correct 215 ms 36592 KB Output is correct
88 Correct 187 ms 30576 KB Output is correct
89 Correct 188 ms 31948 KB Output is correct
90 Correct 257 ms 32048 KB Output is correct
91 Correct 243 ms 32176 KB Output is correct
92 Correct 233 ms 32848 KB Output is correct
93 Correct 281 ms 32180 KB Output is correct
94 Correct 202 ms 32400 KB Output is correct
95 Correct 178 ms 32508 KB Output is correct
96 Correct 144 ms 36284 KB Output is correct
97 Correct 141 ms 24768 KB Output is correct
98 Correct 169 ms 31100 KB Output is correct
99 Correct 182 ms 31296 KB Output is correct
100 Correct 78 ms 17744 KB Output is correct
101 Correct 228 ms 32184 KB Output is correct
102 Correct 201 ms 29096 KB Output is correct
103 Correct 238 ms 29852 KB Output is correct
104 Correct 234 ms 31968 KB Output is correct