Submission #824044

# Submission time Handle Problem Language Result Execution time Memory
824044 2023-08-13T12:09:03 Z Amylopectin Stranded Far From Home (BOI22_island) C++14
0 / 100
177 ms 62004 KB
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int mxn = 1e6 + 10;
struct we
{
    int idx,val;
};
bool cmp(const struct we &l,const struct we &r)
{
    return l.val < r.val;
}
struct we sot[mxn] = {};
char ans[mxn] = {};
int npop[mxn] = {},gr[mxn] = {},he[mxn] = {},siz[mxn] = {},u[mxn] = {};
vector<int> pat[mxn] = {},tre[mxn] = {};
int figr(int l)
{
    int cl = l,f;
    while(l != gr[l])
    {
        l = gr[l];
    }
    while(cl != gr[cl])
    {
        f = gr[cl];
        gr[cl] = l;
        cl = f;
    }
    return l;
}
int mer(int cl,int cr)
{
    int l = figr(cl),r = figr(cr);
    gr[r] = l;
    siz[l] += siz[r];
    return l;
}
int re(int cn)
{
    int i,j,fn;
    ans[cn] = '1';
    for(i=0; i<tre[cn].size(); i++)
    {
        fn = tre[cn][i];
        re(fn);
    }
    return 0;
}
int main()
{
    int i,j,n,m,cn,cm,fn,fm;
    scanf("%d %d",&n,&m);
    for(i=0; i<n; i++)
    {
        scanf("%d",&npop[i]);
        sot[i] = {i,npop[i]};
        he[i] = i;
        gr[i] = i;
        siz[i] = npop[i];
        ans[i] = '0';
    }
    for(i=0; i<m; i++)
    {
        scanf("%d %d",&cn,&cm);
        pat[cn-1].push_back(cm-1);
        pat[cm-1].push_back(cn-1);
    }
    sort(sot,sot+n,cmp);
    for(i=0; i<n; i++)
    {
        cn = sot[i].idx;
        u[cn] = 1;
        for(j=0; j<pat[cn].size(); j++)
        {
            fn = pat[cn][j];
            if(u[fn] == 0)
            {
                continue;
            }
            cm = figr(cn);
            fm = figr(fn);
            if(cm != fm)
            {
                if(siz[fm] >= npop[cn])
                {
                    tre[cn].push_back(he[fm]);
                }
                mer(cm,fm);
            }
        }
    }
    re(sot[n-1].idx);
    printf("%s\n",ans);
    return 0;
}

Compilation message

island.cpp: In function 'int re(int)':
island.cpp:46:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(i=0; i<tre[cn].size(); i++)
      |              ~^~~~~~~~~~~~~~~
island.cpp:44:11: warning: unused variable 'j' [-Wunused-variable]
   44 |     int i,j,fn;
      |           ^
island.cpp: In function 'int main()':
island.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for(j=0; j<pat[cn].size(); j++)
      |                  ~^~~~~~~~~~~~~~~
island.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
island.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         scanf("%d",&npop[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
island.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d %d",&cn,&cm);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47316 KB Output is correct
2 Correct 21 ms 47300 KB Output is correct
3 Correct 24 ms 47272 KB Output is correct
4 Incorrect 21 ms 47372 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 47272 KB Output is correct
2 Correct 20 ms 47296 KB Output is correct
3 Incorrect 134 ms 62004 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47272 KB Output is correct
2 Incorrect 177 ms 61836 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 47244 KB Output is correct
2 Incorrect 177 ms 61684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47316 KB Output is correct
2 Correct 21 ms 47300 KB Output is correct
3 Correct 24 ms 47272 KB Output is correct
4 Incorrect 21 ms 47372 KB Output isn't correct
5 Halted 0 ms 0 KB -