Submission #603969

# Submission time Handle Problem Language Result Execution time Memory
603969 2022-07-24T14:18:30 Z Theo830 Newspapers (CEOI21_newspapers) C++17
8 / 100
14 ms 552 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);
            }
        }
        f(i,0,n){
            if(deg[i] != 1){
                res.clear();
                ok = 1;
                solve(i,0);
                if(ok && res.size() < ans.size()){
                    ans = res;
                }
            }
        }
    }
    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";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 10 ms 552 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 5 ms 448 KB Output is correct
16 Correct 10 ms 468 KB Output is correct
17 Correct 10 ms 452 KB Output is correct
18 Correct 14 ms 468 KB Output is correct
19 Correct 9 ms 468 KB Output is correct
20 Correct 9 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -