답안 #1114617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114617 2024-11-19T09:02:00 Z noyancanturk Newspapers (CEOI21_newspapers) C++17
8 / 100
2 ms 504 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
using pii=pair<int,int>;

signed main(){
  int n,m;
  cin>>n>>m;
  if(n==1){
    cout<<"YES\n1\n1";
    return 0;
  }
  if(n==2){
    cout<<"YES\n2\n1 1";
    return 0;
  }
  if(m!=n-1){
    cout<<"NO\n";
    return 0;
  }
  vector<int>v[n+1];
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    v[x].pb(y);
    v[y].pb(x);
  }
  int cnt=0;
  int cnts[n+1]{};
  for(int i=1;i<=n;i++){
    cnt+=1<v[i].size();
    for(int j:v[i]){
      if(1<v[j].size()){
        cnts[i]++;
      }
    }
  }
  int lf=0;
  int guy=0;
  for(int i=1;i<=n;i++){
    if(v[i].size()>1&&cnts[i]<=1)lf++;
    if(v[i].size()>1&&((!guy&&cnts[i]<=1)||(guy&&cnts[guy]>cnts[i]))){
      guy=i;
    }
  }
  if(2<lf){
    cout<<"NO\n";
    return 0;
  }
  vector<int>chain;
  chain.pb(guy);
  while(1){
    int past=-1;
    if(1<chain.size())past=chain[chain.size()-2];
    int now=chain.back();
    for(int j:v[now]){
      if(j!=past&&v[j].size()>1){
        chain.pb(j);
        break;
      }
    }
    if(chain.back()==now){
      break;
    }
  }
  assert(chain.size()==cnt);
  cout<<"YES\n"<<chain.size()*2<<'\n';
  for(int i=0;i<chain.size();i++){
    cout<<chain[i]<<' ';
  }
  for(int i=chain.size()-1;0<=i;i--){
    cout<<chain[i]<<' ';
  }
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from newspapers.cpp:1:
newspapers.cpp: In function 'int main()':
newspapers.cpp:67:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   67 |   assert(chain.size()==cnt);
      |          ~~~~~~~~~~~~^~~~~
newspapers.cpp:69:16: 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]
   69 |   for(int i=0;i<chain.size();i++){
      |               ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Incorrect 1 ms 336 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 2 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Incorrect 1 ms 336 KB Output isn't correct
9 Halted 0 ms 0 KB -