Submission #604452

# Submission time Handle Problem Language Result Execution time Memory
604452 2022-07-25T06:40:34 Z Theo830 Newspapers (CEOI21_newspapers) C++17
54 / 100
63 ms 12056 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 <= 2){
        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 340 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Partially correct 1 ms 316 KB Failed to provide a successful strategy.
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 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 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 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
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
24 Correct 1 ms 340 KB Output is correct
25 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
26 Partially correct 1 ms 384 KB Failed to provide a successful strategy.
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
31 Correct 1 ms 320 KB Output is correct
32 Partially correct 1 ms 320 KB Failed to provide a successful strategy.
33 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
34 Correct 1 ms 316 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Partially correct 1 ms 372 KB Failed to provide a successful strategy.
37 Partially correct 1 ms 324 KB Failed to provide a successful strategy.
38 Partially correct 1 ms 320 KB Failed to provide a successful strategy.
39 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
40 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
41 Correct 1 ms 324 KB Output is correct
42 Partially correct 1 ms 324 KB Failed to provide a successful strategy.
43 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
44 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Partially correct 1 ms 328 KB Failed to provide a successful strategy.
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 316 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 324 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 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 316 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 324 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 340 KB Output is correct
11 Correct 10 ms 468 KB Output is correct
12 Correct 5 ms 596 KB Output is correct
13 Correct 6 ms 452 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 452 KB Output is correct
16 Correct 11 ms 556 KB Output is correct
17 Correct 11 ms 556 KB Output is correct
18 Correct 11 ms 560 KB Output is correct
19 Correct 10 ms 452 KB Output is correct
20 Correct 11 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 340 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Partially correct 1 ms 316 KB Failed to provide a successful strategy.
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 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 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 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
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
24 Correct 1 ms 340 KB Output is correct
25 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
26 Partially correct 1 ms 384 KB Failed to provide a successful strategy.
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
31 Correct 1 ms 320 KB Output is correct
32 Partially correct 1 ms 320 KB Failed to provide a successful strategy.
33 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
34 Correct 1 ms 316 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Partially correct 1 ms 372 KB Failed to provide a successful strategy.
37 Partially correct 1 ms 324 KB Failed to provide a successful strategy.
38 Partially correct 1 ms 320 KB Failed to provide a successful strategy.
39 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
40 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
41 Correct 1 ms 324 KB Output is correct
42 Partially correct 1 ms 324 KB Failed to provide a successful strategy.
43 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
44 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Partially correct 1 ms 328 KB Failed to provide a successful strategy.
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 316 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 324 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 320 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 316 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Partially correct 1 ms 340 KB Failed to provide a successful strategy.
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 2 ms 340 KB Output is correct
80 Correct 2 ms 340 KB Output is correct
81 Correct 3 ms 452 KB Output is correct
82 Correct 3 ms 340 KB Output is correct
83 Correct 3 ms 340 KB Output is correct
84 Correct 3 ms 340 KB Output is correct
85 Correct 3 ms 340 KB Output is correct
86 Correct 4 ms 460 KB Output is correct
87 Correct 3 ms 340 KB Output is correct
88 Correct 4 ms 340 KB Output is correct
89 Partially correct 10 ms 448 KB Failed to provide a successful strategy.
90 Partially correct 6 ms 468 KB Failed to provide a successful strategy.
91 Partially correct 5 ms 456 KB Failed to provide a successful strategy.
92 Partially correct 3 ms 468 KB Failed to provide a successful strategy.
93 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
94 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
95 Partially correct 7 ms 468 KB Failed to provide a successful strategy.
96 Partially correct 6 ms 468 KB Failed to provide a successful strategy.
97 Partially correct 3 ms 468 KB Failed to provide a successful strategy.
98 Partially correct 5 ms 452 KB Failed to provide a successful strategy.
99 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
100 Partially correct 6 ms 468 KB Failed to provide a successful strategy.
101 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
102 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
103 Partially correct 5 ms 508 KB Failed to provide a successful strategy.
104 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
105 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
106 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
107 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
108 Partially correct 6 ms 468 KB Failed to provide a successful strategy.
109 Partially correct 4 ms 504 KB Failed to provide a successful strategy.
110 Partially correct 4 ms 464 KB Failed to provide a successful strategy.
111 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
112 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
113 Partially correct 6 ms 508 KB Failed to provide a successful strategy.
114 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
115 Partially correct 4 ms 452 KB Failed to provide a successful strategy.
116 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
117 Partially correct 6 ms 452 KB Failed to provide a successful strategy.
118 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
119 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
120 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
121 Partially correct 6 ms 468 KB Failed to provide a successful strategy.
122 Partially correct 5 ms 500 KB Failed to provide a successful strategy.
123 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
124 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
125 Partially correct 4 ms 456 KB Failed to provide a successful strategy.
126 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
127 Partially correct 4 ms 468 KB Failed to provide a successful strategy.
128 Partially correct 5 ms 468 KB Failed to provide a successful strategy.
129 Correct 3 ms 340 KB Output is correct
130 Correct 3 ms 340 KB Output is correct
131 Correct 4 ms 468 KB Output is correct
132 Correct 3 ms 340 KB Output is correct
133 Correct 3 ms 340 KB Output is correct
134 Correct 13 ms 3176 KB Output is correct
135 Correct 11 ms 3148 KB Output is correct
136 Correct 30 ms 5732 KB Output is correct
137 Correct 19 ms 5604 KB Output is correct
138 Correct 31 ms 6068 KB Output is correct
139 Correct 59 ms 10880 KB Output is correct
140 Correct 8 ms 1996 KB Output is correct
141 Correct 4 ms 1104 KB Output is correct
142 Correct 59 ms 10820 KB Output is correct
143 Correct 63 ms 12056 KB Output is correct
144 Correct 10 ms 468 KB Output is correct
145 Correct 11 ms 552 KB Output is correct