답안 #850442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850442 2023-09-16T14:51:30 Z Ahmed57 Stranded Far From Home (BOI22_island) C++17
0 / 100
230 ms 23164 KB
#include <bits/stdc++.h>
using namespace std;
int pr[200001],gs[200001],val[200001];
vector<int> adj[200001],ne[200001];
int find(int x){
    if(x==pr[x])return x;
    return pr[x] = find(pr[x]);
}
bool mergegroup(int a,int b){
    a=find(a),b=find(b);
    if(a==b)return 0;
    pr[b] = a , gs[a]+=gs[b];
    return 1;
}
int main(){
    int n,m;
    cin>>n>>m;
    int arr[n];
    vector<pair<int,int>> v;
    for(int i = 0;i<n;i++){
        cin>>arr[i];val[i] = 1;
        pr[i] = i;gs[i] = arr[i];
        v.push_back({arr[i],i});
    }
    sort(v.begin(),v.end());
    for(int i = 0;i<m;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        if(a>b)swap(a,b);
        if(arr[a]>arr[b])adj[a].push_back(b);
        else if(arr[b]>arr[a])adj[b].push_back(a);
        else adj[b].push_back(a);
    }for(auto i:v){
        int co = i.first , x = i.second;
        for(auto j:adj[x]){
            int lol = find(j) , xd = gs[lol];
            if(mergegroup(lol,x)){
                ne[x].push_back(lol);
                if(xd<co){
                    queue<int> q;q.push(lol);
                    val[lol] = 0;
                    while(!q.empty()){
                        int xx = q.front();q.pop();
                        for(auto j:ne[xx]){
                            if(val[j]){
                                val[j] = 0;
                                q.push(j);
                            }
                        }
                    }
                }
            }
        }
    }
    for(int i = 0;i<n;i++)cout<<val[i];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Incorrect 4 ms 10844 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Incorrect 198 ms 23164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Incorrect 229 ms 22800 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Incorrect 230 ms 22820 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Incorrect 4 ms 10844 KB Output isn't correct
5 Halted 0 ms 0 KB -