Submission #747156

# Submission time Handle Problem Language Result Execution time Memory
747156 2023-05-23T18:58:25 Z Denkata Stranded Far From Home (BOI22_island) C++14
0 / 100
300 ms 54652 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 2e5+3;
long long i,j,p,q,n,m,k;
vector <long long> s[maxn];
long long par[maxn],num[maxn],sum[maxn];
vector <long long> v[maxn];
vector <pair<long long,long long>> g[maxn];
pair <long long,long long> 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(p==q)
        return ;
    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++)
    {
        if(g[i].empty())
            continue;
        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[k])///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;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Incorrect 8 ms 14676 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14356 KB Output is correct
3 Correct 216 ms 48792 KB Output is correct
4 Incorrect 198 ms 48296 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Incorrect 274 ms 54652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14380 KB Output is correct
2 Incorrect 300 ms 50060 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Incorrect 8 ms 14676 KB Output isn't correct
5 Halted 0 ms 0 KB -