답안 #757839

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757839 2023-06-13T19:23:36 Z abcvuitunggio Stranded Far From Home (BOI22_island) C++17
100 / 100
160 ms 34940 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct edge{
    int u,v;
}e[200001];
int n,m,p[200001],a[200001],s[200001];
vector <int> ve[200001];
string res;
int f(int i){
    return (p[i]==i?i:p[i]=f(p[i]));
}
void unite(int u, int v){
    int w=max(s[u],s[v]);
    u=f(u);
    v=f(v);
    if (u==v)
        return;
    if (a[u]<w)
        ve[u].clear();
    if (a[v]<w)
        ve[v].clear();
    if (ve[u].size()<ve[v].size())
        swap(u,v);
    a[u]+=a[v];
    p[v]=u;
    for (int i:ve[v])
        ve[u].push_back(i);
    ve[v].clear();
}
int32_t main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> m;
    for (int i=1;i<=n;i++){
        cin >> s[i];
        a[i]=s[i];
        p[i]=i;
        res+='0';
        ve[i]={i};
    }
    for (int i=0;i<m;i++)
        cin >> e[i].u >> e[i].v;
    sort(e,e+m,[](edge x, edge y){return max(s[x.u],s[x.v])<max(s[y.u],s[y.v]);});
    for (int i=0;i<m;i++)
        unite(e[i].u,e[i].v);
    for (int i:ve[f(1)])
        res[i-1]='1';
    cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 5 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5204 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 3 ms 5204 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 3 ms 5204 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 90 ms 21936 KB Output is correct
4 Correct 131 ms 32764 KB Output is correct
5 Correct 103 ms 24364 KB Output is correct
6 Correct 111 ms 25056 KB Output is correct
7 Correct 124 ms 24984 KB Output is correct
8 Correct 135 ms 29396 KB Output is correct
9 Correct 96 ms 27980 KB Output is correct
10 Correct 79 ms 19432 KB Output is correct
11 Correct 89 ms 21488 KB Output is correct
12 Correct 123 ms 23824 KB Output is correct
13 Correct 136 ms 34920 KB Output is correct
14 Correct 129 ms 33504 KB Output is correct
15 Correct 84 ms 21460 KB Output is correct
16 Correct 61 ms 21312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 129 ms 26628 KB Output is correct
3 Correct 135 ms 26904 KB Output is correct
4 Correct 137 ms 34836 KB Output is correct
5 Correct 145 ms 34708 KB Output is correct
6 Correct 127 ms 26528 KB Output is correct
7 Correct 85 ms 21472 KB Output is correct
8 Correct 83 ms 21496 KB Output is correct
9 Correct 62 ms 21312 KB Output is correct
10 Correct 126 ms 26816 KB Output is correct
11 Correct 118 ms 28976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 127 ms 22596 KB Output is correct
3 Correct 115 ms 23648 KB Output is correct
4 Correct 146 ms 25204 KB Output is correct
5 Correct 137 ms 27956 KB Output is correct
6 Correct 133 ms 24652 KB Output is correct
7 Correct 90 ms 21492 KB Output is correct
8 Correct 73 ms 24976 KB Output is correct
9 Correct 67 ms 15256 KB Output is correct
10 Correct 137 ms 29260 KB Output is correct
11 Correct 141 ms 28328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 5 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5204 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 3 ms 5204 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 3 ms 5204 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 90 ms 21936 KB Output is correct
18 Correct 131 ms 32764 KB Output is correct
19 Correct 103 ms 24364 KB Output is correct
20 Correct 111 ms 25056 KB Output is correct
21 Correct 124 ms 24984 KB Output is correct
22 Correct 135 ms 29396 KB Output is correct
23 Correct 96 ms 27980 KB Output is correct
24 Correct 79 ms 19432 KB Output is correct
25 Correct 89 ms 21488 KB Output is correct
26 Correct 123 ms 23824 KB Output is correct
27 Correct 136 ms 34920 KB Output is correct
28 Correct 129 ms 33504 KB Output is correct
29 Correct 84 ms 21460 KB Output is correct
30 Correct 61 ms 21312 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 129 ms 26628 KB Output is correct
33 Correct 135 ms 26904 KB Output is correct
34 Correct 137 ms 34836 KB Output is correct
35 Correct 145 ms 34708 KB Output is correct
36 Correct 127 ms 26528 KB Output is correct
37 Correct 85 ms 21472 KB Output is correct
38 Correct 83 ms 21496 KB Output is correct
39 Correct 62 ms 21312 KB Output is correct
40 Correct 126 ms 26816 KB Output is correct
41 Correct 118 ms 28976 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 127 ms 22596 KB Output is correct
44 Correct 115 ms 23648 KB Output is correct
45 Correct 146 ms 25204 KB Output is correct
46 Correct 137 ms 27956 KB Output is correct
47 Correct 133 ms 24652 KB Output is correct
48 Correct 90 ms 21492 KB Output is correct
49 Correct 73 ms 24976 KB Output is correct
50 Correct 67 ms 15256 KB Output is correct
51 Correct 137 ms 29260 KB Output is correct
52 Correct 141 ms 28328 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5204 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 3 ms 5076 KB Output is correct
61 Correct 3 ms 5204 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5204 KB Output is correct
64 Correct 4 ms 5204 KB Output is correct
65 Correct 4 ms 5204 KB Output is correct
66 Correct 4 ms 5204 KB Output is correct
67 Correct 89 ms 22036 KB Output is correct
68 Correct 126 ms 32628 KB Output is correct
69 Correct 109 ms 24344 KB Output is correct
70 Correct 112 ms 25040 KB Output is correct
71 Correct 109 ms 24988 KB Output is correct
72 Correct 160 ms 29440 KB Output is correct
73 Correct 94 ms 28004 KB Output is correct
74 Correct 79 ms 19660 KB Output is correct
75 Correct 95 ms 21424 KB Output is correct
76 Correct 132 ms 23836 KB Output is correct
77 Correct 137 ms 34940 KB Output is correct
78 Correct 136 ms 33468 KB Output is correct
79 Correct 92 ms 21464 KB Output is correct
80 Correct 78 ms 21412 KB Output is correct
81 Correct 124 ms 26552 KB Output is correct
82 Correct 137 ms 26904 KB Output is correct
83 Correct 149 ms 34932 KB Output is correct
84 Correct 142 ms 34596 KB Output is correct
85 Correct 130 ms 26592 KB Output is correct
86 Correct 84 ms 21488 KB Output is correct
87 Correct 83 ms 21488 KB Output is correct
88 Correct 110 ms 26760 KB Output is correct
89 Correct 113 ms 28836 KB Output is correct
90 Correct 120 ms 22568 KB Output is correct
91 Correct 123 ms 23620 KB Output is correct
92 Correct 126 ms 25132 KB Output is correct
93 Correct 139 ms 28000 KB Output is correct
94 Correct 131 ms 24512 KB Output is correct
95 Correct 94 ms 21488 KB Output is correct
96 Correct 73 ms 24944 KB Output is correct
97 Correct 63 ms 15232 KB Output is correct
98 Correct 150 ms 29212 KB Output is correct
99 Correct 119 ms 28372 KB Output is correct
100 Correct 45 ms 8376 KB Output is correct
101 Correct 128 ms 23776 KB Output is correct
102 Correct 103 ms 21184 KB Output is correct
103 Correct 102 ms 19156 KB Output is correct
104 Correct 118 ms 21716 KB Output is correct