Submission #744433

# Submission time Handle Problem Language Result Execution time Memory
744433 2023-05-18T14:44:49 Z bgnbvnbv Stranded Far From Home (BOI22_island) C++14
100 / 100
169 ms 42304 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll lab[maxN];
ll sum[maxN];
ll findset(ll x)
{
    return lab[x]<0?x:lab[x]=findset(lab[x]);
}
vector<ll>vec[maxN];
void unite(ll u,ll v,ll w)
{
    u=findset(u);
    v=findset(v);
    if(u==v) return;
    if(lab[u]>lab[v]) swap(u,v);
    if(sum[u]<w)
    {
        if(sum[v]<w)
        {
            vec[u].clear();
        }
        else
        {
            swap(vec[u],vec[v]);
        }
        vec[v].clear();
    }
    else
    {
        if(sum[v]>=w)
        {
            for(auto zz:vec[v]) vec[u].pb(zz);
        }
        vec[v].clear();
    }
    sum[u]+=sum[v];
    lab[u]+=lab[v];
    lab[v]=u;
}
ll n,m,ans[maxN],a[maxN];
struct edge
{
    ll u,v,w;
    bool operator<(const edge&o)
    {
        return w<o.w;
    }
}e[maxN];
void solve()
{
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> a[i],vec[i].pb(i),ans[i]=0,sum[i]=a[i],lab[i]=-1;
    for(int i=1;i<=m;i++)
    {
        cin >> e[i].u >> e[i].v;
        e[i].w=max(a[e[i].u],a[e[i].v]);
    }
    sort(e+1,e+m+1);
    for(int i=1;i<=m;i++)
    {
        unite(e[i].u,e[i].v,e[i].w);
    }
    ll x=findset(1);
    for(auto zz:vec[x])
    {
        ans[zz]=1;
    }
    for(int i=1;i<=n;i++) cout << ans[i];

}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 3 ms 5152 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 5204 KB Output is correct
10 Correct 4 ms 5312 KB Output is correct
11 Correct 4 ms 5308 KB Output is correct
12 Correct 5 ms 5204 KB Output is correct
13 Correct 4 ms 5332 KB Output is correct
14 Correct 4 ms 5180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5040 KB Output is correct
3 Correct 105 ms 29392 KB Output is correct
4 Correct 132 ms 38596 KB Output is correct
5 Correct 119 ms 31396 KB Output is correct
6 Correct 119 ms 32416 KB Output is correct
7 Correct 130 ms 32368 KB Output is correct
8 Correct 151 ms 36796 KB Output is correct
9 Correct 116 ms 35388 KB Output is correct
10 Correct 98 ms 25932 KB Output is correct
11 Correct 105 ms 27868 KB Output is correct
12 Correct 123 ms 29992 KB Output is correct
13 Correct 136 ms 40724 KB Output is correct
14 Correct 133 ms 39552 KB Output is correct
15 Correct 99 ms 28844 KB Output is correct
16 Correct 78 ms 27964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 131 ms 33976 KB Output is correct
3 Correct 127 ms 34248 KB Output is correct
4 Correct 155 ms 42304 KB Output is correct
5 Correct 134 ms 40584 KB Output is correct
6 Correct 128 ms 34256 KB Output is correct
7 Correct 97 ms 28904 KB Output is correct
8 Correct 106 ms 28864 KB Output is correct
9 Correct 75 ms 27872 KB Output is correct
10 Correct 117 ms 33600 KB Output is correct
11 Correct 130 ms 34648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5044 KB Output is correct
2 Correct 149 ms 30092 KB Output is correct
3 Correct 123 ms 30892 KB Output is correct
4 Correct 127 ms 32540 KB Output is correct
5 Correct 140 ms 35352 KB Output is correct
6 Correct 129 ms 31684 KB Output is correct
7 Correct 97 ms 28812 KB Output is correct
8 Correct 90 ms 31120 KB Output is correct
9 Correct 68 ms 20044 KB Output is correct
10 Correct 133 ms 35076 KB Output is correct
11 Correct 124 ms 34272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 3 ms 5152 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 5204 KB Output is correct
10 Correct 4 ms 5312 KB Output is correct
11 Correct 4 ms 5308 KB Output is correct
12 Correct 5 ms 5204 KB Output is correct
13 Correct 4 ms 5332 KB Output is correct
14 Correct 4 ms 5180 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5040 KB Output is correct
17 Correct 105 ms 29392 KB Output is correct
18 Correct 132 ms 38596 KB Output is correct
19 Correct 119 ms 31396 KB Output is correct
20 Correct 119 ms 32416 KB Output is correct
21 Correct 130 ms 32368 KB Output is correct
22 Correct 151 ms 36796 KB Output is correct
23 Correct 116 ms 35388 KB Output is correct
24 Correct 98 ms 25932 KB Output is correct
25 Correct 105 ms 27868 KB Output is correct
26 Correct 123 ms 29992 KB Output is correct
27 Correct 136 ms 40724 KB Output is correct
28 Correct 133 ms 39552 KB Output is correct
29 Correct 99 ms 28844 KB Output is correct
30 Correct 78 ms 27964 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 131 ms 33976 KB Output is correct
33 Correct 127 ms 34248 KB Output is correct
34 Correct 155 ms 42304 KB Output is correct
35 Correct 134 ms 40584 KB Output is correct
36 Correct 128 ms 34256 KB Output is correct
37 Correct 97 ms 28904 KB Output is correct
38 Correct 106 ms 28864 KB Output is correct
39 Correct 75 ms 27872 KB Output is correct
40 Correct 117 ms 33600 KB Output is correct
41 Correct 130 ms 34648 KB Output is correct
42 Correct 3 ms 5044 KB Output is correct
43 Correct 149 ms 30092 KB Output is correct
44 Correct 123 ms 30892 KB Output is correct
45 Correct 127 ms 32540 KB Output is correct
46 Correct 140 ms 35352 KB Output is correct
47 Correct 129 ms 31684 KB Output is correct
48 Correct 97 ms 28812 KB Output is correct
49 Correct 90 ms 31120 KB Output is correct
50 Correct 68 ms 20044 KB Output is correct
51 Correct 133 ms 35076 KB Output is correct
52 Correct 124 ms 34272 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 5036 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 5 ms 5204 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 4 ms 5204 KB Output is correct
59 Correct 4 ms 5204 KB Output is correct
60 Correct 3 ms 5172 KB Output is correct
61 Correct 3 ms 5204 KB Output is correct
62 Correct 4 ms 5332 KB Output is correct
63 Correct 3 ms 5204 KB Output is correct
64 Correct 4 ms 5332 KB Output is correct
65 Correct 3 ms 5332 KB Output is correct
66 Correct 4 ms 5204 KB Output is correct
67 Correct 103 ms 29384 KB Output is correct
68 Correct 127 ms 38600 KB Output is correct
69 Correct 118 ms 31428 KB Output is correct
70 Correct 116 ms 32360 KB Output is correct
71 Correct 140 ms 32356 KB Output is correct
72 Correct 141 ms 36732 KB Output is correct
73 Correct 113 ms 35348 KB Output is correct
74 Correct 85 ms 25896 KB Output is correct
75 Correct 94 ms 27840 KB Output is correct
76 Correct 122 ms 29960 KB Output is correct
77 Correct 137 ms 40772 KB Output is correct
78 Correct 169 ms 39560 KB Output is correct
79 Correct 97 ms 28840 KB Output is correct
80 Correct 77 ms 27968 KB Output is correct
81 Correct 145 ms 33976 KB Output is correct
82 Correct 132 ms 34244 KB Output is correct
83 Correct 158 ms 42300 KB Output is correct
84 Correct 135 ms 40488 KB Output is correct
85 Correct 143 ms 34148 KB Output is correct
86 Correct 97 ms 28900 KB Output is correct
87 Correct 96 ms 28792 KB Output is correct
88 Correct 125 ms 33576 KB Output is correct
89 Correct 116 ms 34716 KB Output is correct
90 Correct 127 ms 30016 KB Output is correct
91 Correct 119 ms 30916 KB Output is correct
92 Correct 123 ms 32548 KB Output is correct
93 Correct 161 ms 35380 KB Output is correct
94 Correct 145 ms 31724 KB Output is correct
95 Correct 97 ms 28732 KB Output is correct
96 Correct 83 ms 31144 KB Output is correct
97 Correct 65 ms 20196 KB Output is correct
98 Correct 145 ms 35168 KB Output is correct
99 Correct 134 ms 34248 KB Output is correct
100 Correct 44 ms 11852 KB Output is correct
101 Correct 125 ms 31184 KB Output is correct
102 Correct 107 ms 27880 KB Output is correct
103 Correct 118 ms 25924 KB Output is correct
104 Correct 128 ms 28996 KB Output is correct