답안 #603976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603976 2022-07-24T14:22:29 Z Theo830 Newspapers (CEOI21_newspapers) C++17
8 / 100
31 ms 556 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
bool ok = 1;
vector<vll>adj;
vll res;
void solve(ll idx,ll p){
    res.pb(idx+1);
    bool f = 1;
    ll posa = 0;
    for(auto x:adj[idx]){
        if(x != p){
            if(f){
                f = 0;
            }
            else{
                res.pb(idx+1);
            }
            solve(x,idx);
            posa += adj[x].size() != 1;
        }
    }
    if(posa > 1){
        ok = 0;
    }
}
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    adj.assign(n+5,vll());
    ll deg[n] = {0};
    vector<ii>ed;
    vll ans;
    f(i,0,5000){
        ans.pb(i);
    }
    f(i,0,m){
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        deg[a]++;
        deg[b]++;
        ed.pb(ii(a,b));
    }
    ok = m == n-1;
    if(ok){
        for(auto x:ed){
            if(deg[x.F] != 1 && deg[x.S] != 1){
                adj[x.F].pb(x.S);
                adj[x.S].pb(x.F);
            }
        }
        bool ivra = 0;
        f(i,0,n){
            if(deg[i] != 1){
                res.clear();
                ok = 1;
                solve(i,-1);
                if(ok && res.size() < ans.size()){
                    ans = res;
                }
                ivra |= ok;
            }
        }
        ok = ivra;
    }
    if(n == 1){
        cout<<"YES\n";
        cout<<"1\n 1\n";
    }
    else if(n <= 3){
        cout<<"YES\n";
        cout<<"2\n2 2\n";
    }
    else if(ok){
        cout<<"YES\n";
        cout<<2 * ans.size()<<"\n";
        for(auto x:ans){
            cout<<x<<" ";
        }
        if(ans.size() % 2 == 0){
            reverse(all(ans));
        }
        for(auto x:ans){
            cout<<x<<" ";
        }
    }
    else{
        cout<<"NO\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 9 ms 548 KB Output is correct
12 Correct 6 ms 468 KB Output is correct
13 Correct 10 ms 456 KB Output is correct
14 Correct 5 ms 468 KB Output is correct
15 Correct 6 ms 468 KB Output is correct
16 Correct 10 ms 468 KB Output is correct
17 Correct 31 ms 468 KB Output is correct
18 Correct 11 ms 468 KB Output is correct
19 Correct 10 ms 468 KB Output is correct
20 Correct 13 ms 556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -