답안 #824042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824042 2023-08-13T12:08:34 Z Amylopectin Boarding Passes (BOI22_passes) C++14
0 / 100
120 ms 137292 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

passes.cpp: In function 'int re(int)':
passes.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++)
      |              ~^~~~~~~~~~~~~~~
passes.cpp:44:11: warning: unused variable 'j' [-Wunused-variable]
   44 |     int i,j,fn;
      |           ^
passes.cpp: In function 'int main()':
passes.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++)
      |                  ~^~~~~~~~~~~~~~~
passes.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);
      |     ~~~~~^~~~~~~~~~~~~~~
passes.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]);
      |         ~~~~~^~~~~~~~~~~~~~~
passes.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);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 118 ms 137292 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 120 ms 137224 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 120 ms 137224 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 118 ms 137292 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -