답안 #810974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
810974 2023-08-06T18:47:24 Z owoovo Stranded Far From Home (BOI22_island) C++17
15 / 100
335 ms 524288 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,tag[200010],subsum[200010],dsu[200010],ans[200010];
vector<ll> e[200010],te[200010];
pair<ll,ll> val[200010];
int f(int now){
    if(dsu[now]!=now) dsu[now]=f(dsu[now]);
    return dsu[now];
}
void dfs(int now,int x){
    tag[now]==1?ans[now]=0:ans[now]=x;
    for(auto ne:te[now]){
        dfs(ne,ans[now]);
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    int last=1;
    for(int i=1;i<=n;i++){
        cin>>val[i].first;
        val[i].second=i;
        dsu[i]=i;
        subsum[i]=val[i].first;
    }
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;  
        if(val[a].first>val[b].first)e[a].push_back(b);
        else e[b].push_back(a);
    }
    sort(&val[1],&val[n+1]);
    for(int i=1;i<=n;i++){
        ll x=val[i].second;
        ll y=val[i].first;
        for(auto ne:e[x]){
            ne=f(ne);
            if(ne==x)continue;
            te[x].push_back(ne);
            if(subsum[ne]<y)tag[ne]=1;
            dsu[ne]=x;
            subsum[x]+=subsum[ne];
        }
    }
    dfs(val[n].second,1);
    for(int i=1;i<=n;i++)cout<<ans[i];
    cout<<"\n";
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:21:9: warning: unused variable 'last' [-Wunused-variable]
   21 |     int last=1;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 5 ms 9812 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Runtime error 265 ms 524288 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 105 ms 31920 KB Output is correct
4 Incorrect 88 ms 30852 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 137 ms 27444 KB Output is correct
3 Correct 133 ms 27636 KB Output is correct
4 Correct 112 ms 31692 KB Output is correct
5 Correct 96 ms 30240 KB Output is correct
6 Correct 133 ms 27560 KB Output is correct
7 Correct 113 ms 39580 KB Output is correct
8 Correct 109 ms 39624 KB Output is correct
9 Correct 72 ms 39224 KB Output is correct
10 Correct 87 ms 30240 KB Output is correct
11 Correct 112 ms 29156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Runtime error 335 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 5 ms 9812 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Runtime error 265 ms 524288 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -