답안 #747153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747153 2023-05-23T18:40:43 Z Denkata Stranded Far From Home (BOI22_island) C++14
0 / 100
1000 ms 39260 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 2e5+3;
int i,j,p,q,n,m,k;
vector <int> s[maxn];
int par[maxn],num[maxn],sum[maxn];
vector <int> v[maxn];
vector <pair<int,int>> g[maxn];
pair <int,int> obh[maxn];
bool covered[maxn];
int Find(int p)
{
    if(par[p]==p)
        return p;
    return Find(par[p]);
}
void Union(int p,int q)
{
    p = Find(p);
    q = Find(q);
    if(s[p].size()<s[q].size())
        swap(p,q);
    par[q] = p;
    sum[p] += sum[q];
    for(auto jj:s[q])
        s[p].push_back(jj);
    s[q].clear();//reserve
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    vector <char> c(n);
    for(i=1;i<=n;i++)
    {
        cin>>num[i];
        obh[i] = {num[i],i};
    }
    sort(obh+1,obh+n+1);
    for(i=1;i<=m;i++)
    {
        cin>>p>>q;
        g[p].push_back({num[q],q});
        g[q].push_back({num[p],p});
    }
    for(i=1;i<=n;i++)
    {
        sort(g[i].begin(),g[i].end());
        for(auto j:g[i])
            v[i].push_back(j.second);
    }
    for(i=1;i<=n;i++)
    {
        par[i] = i;
        sum[i] = num[i];
        s[i].push_back(i);
    }
    for(i=1;i<=n;i++)
    {
        p = obh[i].second;
        covered[p] = true;
        k = Find(p);
        for(auto j:v[p])
        {
            int pp = Find(j);
            if(pp==k || covered[j])continue;
           // cout<<j<<endl;
            if(num[j]>sum[p])///can't proceed further
            {
                s[k].clear();
            }
            Union(k,pp);
        }
    }
    p = Find(1);
    for(i=0;i<n;i++)
        c[i] = '0';
    for(auto i:s[p])
        c[i-1] = '1';
    for(auto i:c)
        cout<<i;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14428 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14428 KB Output is correct
4 Incorrect 10 ms 14676 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Incorrect 180 ms 38752 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Incorrect 239 ms 38320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Execution timed out 1073 ms 39260 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14428 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14428 KB Output is correct
4 Incorrect 10 ms 14676 KB Output isn't correct
5 Halted 0 ms 0 KB -