답안 #546389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546389 2022-04-07T12:33:52 Z yutabi Newspapers (CEOI21_newspapers) C++14
6 / 100
1 ms 340 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");

        return 0;
    }

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

        return 0;
    }

    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:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for(int j=0;j<tree[i].size();j++)
      |                     ~^~~~~~~~~~~~~~~
newspapers.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         for(int i=0;i<tree[curr].size();i++)
      |                     ~^~~~~~~~~~~~~~~~~~
newspapers.cpp:108:19: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
  108 |     printf("YES\n%d\n",ans.size()*2);
      |                  ~^    ~~~~~~~~~~~~
      |                   |              |
      |                   int            std::vector<int>::size_type {aka long unsigned int}
      |                  %ld
newspapers.cpp:110:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     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:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf(" %d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Partially correct 1 ms 296 KB Provide a successful but not optimal strategy.
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -