Submission #654415

# Submission time Handle Problem Language Result Execution time Memory
654415 2022-10-31T09:10:50 Z ktkerem Stranded Far From Home (BOI22_island) C++17
0 / 100
120 ms 22732 KB
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll , ll> llll;
#define fi first
#define sec second
#define all(x)  x.begin() , x.end()
#define pb push_back
const ll ous = 1e5+7;
std::vector<llll> ar ;std::vector<ll> adj[ous] , nds(ous , 0) , par(ous) , sz(ous) , ans(ous , 1) , rar(ous) , kr(ous) , ant(ous);
ll n , m , o;
ll fin(ll x){
    if(par[x] == x){
        return x;
    }
    return par[x] = fin(par[x]);
}
void mrg(ll x , ll y){
    x = fin(x);y = fin(y);
    if(sz[y] > sz[x]){
        std::swap(x , y);
    }
    if(x != y){
        par[y] = x;
        sz[x] += sz[y]; 
    }
}
void dfs(ll crt){
    o += rar[crt];
    nds[crt] = 1;
    for(auto j:adj[crt]){
        if(fin(crt) != fin(j) && nds[j] == 0){
            mrg(crt , j);
            dfs(j);
        }
    }
}
void solve(){
    ll n , m;std::cin >> n >> m;
    ar.resize(n);
    for(ll i = 0;n>i;i++){
        std::cin >> ar[i].fi;
        ar[i].sec = i + 1;
        rar[i+1] = ar[i].fi;
    }
    for(ll i = 0;m>i;i++){
        ll x , y;std::cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    std::sort(all(ar) , std::greater<llll>());
    ll ik = 1;
    for(;n > ik;ik++){
        if(ar[ik].fi != ar[ik-1].fi){
            break;
        }
    }
    while(n > ik){
        for(ll i = 0;n>+i;i++){
            par[i] = i;
            sz[i] = 1;
            nds[i] = 0;
            kr[i] = 0;
        }
        for(ll i = 0;ik>i;i++){
            nds[ar[i].sec] = 1; 
        }
        for(ll i = ik;n>i;i++){
            ans[ar[i].sec] = 0;
        }
        for(ll i = 1;n>+i;i++){
            if(nds[i] == 0){
                dfs(i);
                kr[fin(i)] = o;
                o = 0;
            }
        }
        for(ll i = 0;ik>i;i++){
            for(auto j:adj[ar[i].sec]){
                ll ff = fin(j);
                if(kr[ff] >= ar[i].fi){
                    ant[ff] |= ans[ar[i].sec];
                }
            }
        }
        for(ll i = 1;n>+i;i++){
            ans[i] |= ant[fin(i)];
        }
        ik++;
        for(;n > ik;ik++){
            if(ar[ik-1].fi != ar[ik].fi){
                break;
            }
        }
    }
    for(ll i = 1;n>=i;i++){
        std::cout << ans[i];
    }
    std::cout <<"\n";

}
signed main(){
    std::ios_base::sync_with_stdio(false);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 4 ms 8276 KB Output is correct
4 Incorrect 120 ms 8276 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8156 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Runtime error 32 ms 22620 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8172 KB Output is correct
2 Runtime error 44 ms 22680 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8068 KB Output is correct
2 Runtime error 34 ms 22732 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 4 ms 8276 KB Output is correct
4 Incorrect 120 ms 8276 KB Output isn't correct
5 Halted 0 ms 0 KB -