Submission #546388

# Submission time Handle Problem Language Result Execution time Memory
546388 2022-04-07T12:31:55 Z yutabi Newspapers (CEOI21_newspapers) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

int n,m;

int start;

vector <vector <int> > tree;

vector <int> ans;


int main()
{
    scanf("%d %d",&n,&m);

    if(n==1)
    {
        printf("YES\n1\n1");
    }

    if(n==2)
    {
        printf("YES\n2\n1 1");
    }

    if(m>=n)
    {
        printf("NO");

        return 0;
    }

    tree=vector <vector <int> > (n);

    for(int i=0;i<m;i++)
    {
        int a,b;

        scanf(" %d %d",&a,&b);
        a--,b--;

        tree[a].pb(b);
        tree[b].pb(a);
    }

    for(int i=0;i<n;i++)
    {
        if(tree[i].size()==1)
        {
            continue;
        }

        int a=0;

        for(int j=0;j<tree[i].size();j++)
        {
            if(tree[tree[i][j]].size()!=1)
            {
                a++;
            }
        }

        if(a==1)
        {
            start=i;
        }

        if(a>2)
        {
            printf("NO");

            return 0;
        }
    }

    int curr=start;
    int last=-1;

    while(1)
    {
        if(ans.size() && ans.back()==curr)
        {
            break;
        }

        ans.pb(curr);

        for(int i=0;i<tree[curr].size();i++)
        {
            if(tree[curr][i]!=last && tree[tree[curr][i]].size()!=1)
            {
                last=curr;

                curr=tree[curr][i];

                break;
            }
        }
    }

    printf("YES\n%d\n",ans.size()*2);

    for(int i=0;i<ans.size();i++)
    {
        printf("%d ",ans[i]+1);
    }

    for(int i=ans.size()-1;i>=0;i--)
    {
        printf("%d ",ans[i]+1);
    }
}

Compilation message

newspapers.cpp: In function 'int main()':
newspapers.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int j=0;j<tree[i].size();j++)
      |                     ~^~~~~~~~~~~~~~~
newspapers.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         for(int i=0;i<tree[curr].size();i++)
      |                     ~^~~~~~~~~~~~~~~~~~
newspapers.cpp:104:19: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
  104 |     printf("YES\n%d\n",ans.size()*2);
      |                  ~^    ~~~~~~~~~~~~
      |                   |              |
      |                   int            std::vector<int>::size_type {aka long unsigned int}
      |                  %ld
newspapers.cpp:106:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for(int i=0;i<ans.size();i++)
      |                 ~^~~~~~~~~~~
newspapers.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
newspapers.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf(" %d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "1YES" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "1YES" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "1YES" found
2 Halted 0 ms 0 KB -