Submission #757835

# Submission time Handle Problem Language Result Execution time Memory
757835 2023-06-13T19:16:04 Z abcvuitunggio Stranded Far From Home (BOI22_island) C++17
0 / 100
145 ms 23772 KB
#include <bits/stdc++.h>
using namespace std;
struct edge{
    int u,v;
}e[200001];
int n,m,p[200001],a[200001];
set <int> s[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(a[u],a[v]);
    u=f(u);
    v=f(v);
    if (u==v)
        return;
    if (a[u]<w)
        s[u].clear();
    if (a[v]<w)
        s[v].clear();
    if (s[u].size()<s[v].size())
        swap(u,v);
    a[u]+=a[v];
    p[v]=u;
    for (int i:s[v])
        s[u].insert(i);
    s[v].clear();
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> m;
    for (int i=1;i<=n;i++){
        cin >> a[i];
        p[i]=i;
        res+='0';
        s[i].insert(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(a[x.u],a[x.v])<max(a[y.u],a[y.v]);});
    for (int i=0;i<m;i++)
        unite(e[i].u,e[i].v);
    for (int i:s[f(1)])
        res[i-1]='1';
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 6 ms 9864 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9720 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 112 ms 23748 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 145 ms 23772 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Incorrect 134 ms 23768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 6 ms 9864 KB Output isn't correct
5 Halted 0 ms 0 KB -