Submission #823809

#TimeUsernameProblemLanguageResultExecution timeMemory
823809AmylopectinStranded Far From Home (BOI22_island)C++14
10 / 100
1074 ms34780 KiB
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const long long mxn = 1e6 + 10;
struct we
{
    long long noo,cva;
    bool operator() (const struct we &l,const struct we &r)
    {
        return l.cva > r.cva;
    }
};
long long npop[mxn] = {},u[mxn] = {};
char ans[mxn] = {};
priority_queue<struct we,vector<struct we>,struct we> qu;
vector<long long> pat[mxn] = {};
int main()
{
    long long i,j,n,m,cn,cm,fn,fm,cou,cva;
    scanf("%lld %lld",&n,&m);
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&npop[i]);
    }
    for(i=0; i<m; i++)
    {
        scanf("%lld %lld",&cn,&cm);
        pat[cn].push_back(cm);
        pat[cm].push_back(cn);
    }
    for(i=1; i<=n; i++)
    {
        qu.push({i,npop[i]});
        u[i] = i;
        cou = 0;
        cva = 0;
        while(!qu.empty())
        {
            cn = qu.top().noo;
            qu.pop();
            if(cou > 0 && cva < npop[cn])
            {
                break;
            }
            cou ++;
            cva += npop[cn];
            for(j=0; j<pat[cn].size(); j++)
            {
                fn = pat[cn][j];
                if(u[fn] != i)
                {
                    qu.push({fn,npop[fn]});
                    u[fn] = i;
                }
            }
        }
        while(!qu.empty())
        {
            qu.pop();
        }
        if(cou == n)
        {
            ans[i-1] = '1';
        }
        else 
        {
            ans[i-1] = '0';
        }
    }
    printf("%s\n",ans);
}

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:49:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             for(j=0; j<pat[cn].size(); j++)
      |                      ~^~~~~~~~~~~~~~~
island.cpp:21:32: warning: unused variable 'fm' [-Wunused-variable]
   21 |     long long i,j,n,m,cn,cm,fn,fm,cou,cva;
      |                                ^~
island.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%lld %lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
island.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%lld",&npop[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
island.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%lld %lld",&cn,&cm);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...