답안 #541588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541588 2022-03-23T19:39:19 Z mat_v Newspapers (CEOI21_newspapers) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n,m;

vector<int> graf[1005];
int deg[1005];
int pom[1005];
vector<int> v;

bool bio[1005];

void dfs(int x){
    bio[x] = 1;
    v.pb(x);
    v.pb(x);
    for(auto c:graf[x]){
        if(bio[c])continue;
        if(deg[c] == 1)continue;
        dfs(c);
    }
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    ff(i,1,m){
        int a,b;
        cin >> a >> b;
        graf[a].pb(b);
        graf[b].pb(a);
        deg[a]++;
        deg[b]++;

    }
    if(m >= n){
        cout << "NO\n";
        return 0;
    }
    if(n == 2){
        cout << "YES\n";
        cout << 2 << "\n" << 1 << " " << 1 << "\n";
        return 0;
    }
    ff(i,1,n){
        int klk = 0;
        for(auto c:graf[i]){
            if(deg[c]>1)klk++;
        }
        pom[i] = klk;
        if(klk >= 3){
            cout << "NO\n";
            return 0;
        }
    }
    int poc = 0;
    ff(i,1,n){
        if(pom[i] <= 1 && deg[i] > 1)poc = i;
    }
    dfs(poc);
    cout << "YES\n";
    cout << v.size() << "\n";
    for(auto c:v)cout << c << " ";
    return 0;
}

Compilation message

newspapers.cpp: In function 'int main()':
newspapers.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
newspapers.cpp:48:5: note: in expansion of macro 'ff'
   48 |     ff(i,1,m){
      |     ^~
newspapers.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
newspapers.cpp:66:5: note: in expansion of macro 'ff'
   66 |     ff(i,1,n){
      |     ^~
newspapers.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
newspapers.cpp:78:5: note: in expansion of macro 'ff'
   78 |     ff(i,1,n){
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Integer 0 violates the range [1, 1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Integer 0 violates the range [1, 1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Integer 0 violates the range [1, 1]
2 Halted 0 ms 0 KB -