Submission #931021

# Submission time Handle Problem Language Result Execution time Memory
931021 2024-02-21T05:43:18 Z Darren0724 Stranded Far From Home (BOI22_island) C++17
0 / 100
222 ms 64596 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
const int N=200005;
const int INF=1e18;
const int mod=1e9+9;
vector<int> pa(N);
int Find(int k){
    if(k<0)while(1){}
    return (pa[k]==k?k:pa[k]=Find(pa[k]));
}
void onion(int a,int b,vector<int> &pw){
    a=Find(a),b=Find(b);
    if(a==b)return;
    pa[a]=b;
    pw[b]+=pw[a];
}
int cnt1=0;
void dfs(int k,int flag,vector<int> &can,vector<int> adj[]){
    cnt1++;
    while(cnt1>=10000){}
    can[k]&=flag;
    for(int j:adj[k]){
        dfs(j,can[k],can,adj);
    }
}
int32_t main() {
    LCBorz;
    iota(all(pa),0);
    int n,m;cin>>n>>m;
    vector<int> v(n+1),pw(n+1),t(n),use(n+1);
    vector<int> adj[n+1],can(n+1,1),g[n+1],ing(n+1);
    for(int i=1;i<=n;i++){
        cin>>v[i];pw[i]=v[i];
    }
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    iota(all(t),1);
    sort(all(t),[&](int a,int b){return v[a]<v[b];});
    for(int i:t){
        for(int j:adj[i]){
            if(!use[j])continue;
            int t=Find(j);
            if(pw[t]<v[i])can[j]=0;
            if(!ing[t]){
                ing[t]=1;
                g[i].push_back(t);
            }
        }
        for(int j:adj[i]){
            if(use[j])ing[Find(j)]=0;
        }
        for(int j:adj[i]){
            if(use[j])onion(j,i,pw);
        }
        use[i]=1;
    }
    dfs(v[n-1],1,can,g);
    for(int i=1;i<=n;i++){
        cout<<can[i];
    }
    cout<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Runtime error 3 ms 4188 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 128 ms 36272 KB Output is correct
4 Incorrect 117 ms 33528 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Runtime error 222 ms 62508 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Runtime error 173 ms 64596 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Runtime error 3 ms 4188 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -