Submission #604466

# Submission time Handle Problem Language Result Execution time Memory
604466 2022-07-25T06:47:13 Z Theo830 Newspapers (CEOI21_newspapers) C++17
54 / 100
69 ms 43772 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;
ll c[1005] = {0};
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);
            }
            c[x] = c[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;
    vll w[n];
    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){
            f(j,0,5000){
                w[i].pb(j);
            }
        }
        f(i,0,n){
            if(deg[i] != 1){
                res.clear();
                ok = 1;
                solve(i,-1);
                if(ok){
                    w[i] = res;
                }
                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){
            bool ek = 0;
            f(i,0,n){
                if(c[i] != c[ans[0]-1] && w[i].size() == ans.size()){
                    ans = w[i];
                    ek = 1;
                    break;
                }
            }
            if(!ek){
                ans.insert(ans.begin(),1);
            }
        }
        for(auto x:ans){
            cout<<x<<" ";
        }
    }
    else{
        cout<<"NO\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Partially correct 1 ms 724 KB Failed to provide a successful strategy.
11 Correct 1 ms 724 KB Output is correct
12 Partially correct 1 ms 724 KB Failed to provide a successful strategy.
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 852 KB Output is correct
23 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
24 Correct 2 ms 980 KB Output is correct
25 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
26 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
27 Correct 1 ms 980 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Partially correct 1 ms 1020 KB Failed to provide a successful strategy.
31 Correct 1 ms 980 KB Output is correct
32 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
33 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
34 Correct 2 ms 980 KB Output is correct
35 Correct 1 ms 1108 KB Output is correct
36 Partially correct 2 ms 1108 KB Failed to provide a successful strategy.
37 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
38 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
39 Partially correct 3 ms 1108 KB Failed to provide a successful strategy.
40 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
41 Correct 1 ms 1108 KB Output is correct
42 Partially correct 1 ms 1116 KB Failed to provide a successful strategy.
43 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
44 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
45 Correct 1 ms 1108 KB Output is correct
46 Correct 1 ms 1108 KB Output is correct
47 Correct 1 ms 1236 KB Output is correct
48 Partially correct 1 ms 1248 KB Failed to provide a successful strategy.
49 Correct 1 ms 1236 KB Output is correct
50 Correct 2 ms 1236 KB Output is correct
51 Partially correct 2 ms 1236 KB Failed to provide a successful strategy.
52 Correct 2 ms 1236 KB Output is correct
53 Correct 1 ms 1236 KB Output is correct
54 Correct 1 ms 1236 KB Output is correct
55 Correct 1 ms 1236 KB Output is correct
56 Correct 2 ms 1236 KB Output is correct
57 Correct 2 ms 1232 KB Output is correct
58 Correct 2 ms 1236 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 412 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 1 ms 872 KB Output is correct
11 Correct 59 ms 41420 KB Output is correct
12 Correct 28 ms 22692 KB Output is correct
13 Correct 31 ms 26836 KB Output is correct
14 Correct 31 ms 28316 KB Output is correct
15 Correct 42 ms 29812 KB Output is correct
16 Correct 52 ms 43604 KB Output is correct
17 Correct 55 ms 43640 KB Output is correct
18 Correct 51 ms 43684 KB Output is correct
19 Correct 55 ms 43660 KB Output is correct
20 Correct 54 ms 43772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Partially correct 1 ms 724 KB Failed to provide a successful strategy.
11 Correct 1 ms 724 KB Output is correct
12 Partially correct 1 ms 724 KB Failed to provide a successful strategy.
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 852 KB Output is correct
23 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
24 Correct 2 ms 980 KB Output is correct
25 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
26 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
27 Correct 1 ms 980 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Partially correct 1 ms 1020 KB Failed to provide a successful strategy.
31 Correct 1 ms 980 KB Output is correct
32 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
33 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
34 Correct 2 ms 980 KB Output is correct
35 Correct 1 ms 1108 KB Output is correct
36 Partially correct 2 ms 1108 KB Failed to provide a successful strategy.
37 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
38 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
39 Partially correct 3 ms 1108 KB Failed to provide a successful strategy.
40 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
41 Correct 1 ms 1108 KB Output is correct
42 Partially correct 1 ms 1116 KB Failed to provide a successful strategy.
43 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
44 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
45 Correct 1 ms 1108 KB Output is correct
46 Correct 1 ms 1108 KB Output is correct
47 Correct 1 ms 1236 KB Output is correct
48 Partially correct 1 ms 1248 KB Failed to provide a successful strategy.
49 Correct 1 ms 1236 KB Output is correct
50 Correct 2 ms 1236 KB Output is correct
51 Partially correct 2 ms 1236 KB Failed to provide a successful strategy.
52 Correct 2 ms 1236 KB Output is correct
53 Correct 1 ms 1236 KB Output is correct
54 Correct 1 ms 1236 KB Output is correct
55 Correct 1 ms 1236 KB Output is correct
56 Correct 2 ms 1236 KB Output is correct
57 Correct 2 ms 1232 KB Output is correct
58 Correct 2 ms 1236 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 412 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 1 ms 468 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 1 ms 596 KB Output is correct
68 Correct 1 ms 744 KB Output is correct
69 Correct 1 ms 596 KB Output is correct
70 Correct 1 ms 724 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 724 KB Output is correct
73 Correct 1 ms 852 KB Output is correct
74 Partially correct 1 ms 724 KB Failed to provide a successful strategy.
75 Correct 1 ms 724 KB Output is correct
76 Partially correct 1 ms 724 KB Failed to provide a successful strategy.
77 Correct 1 ms 724 KB Output is correct
78 Correct 1 ms 596 KB Output is correct
79 Correct 39 ms 36176 KB Output is correct
80 Correct 43 ms 37116 KB Output is correct
81 Correct 37 ms 37580 KB Output is correct
82 Correct 44 ms 40832 KB Output is correct
83 Correct 47 ms 39116 KB Output is correct
84 Correct 41 ms 37428 KB Output is correct
85 Correct 34 ms 37412 KB Output is correct
86 Correct 36 ms 37976 KB Output is correct
87 Correct 34 ms 38988 KB Output is correct
88 Correct 30 ms 35156 KB Output is correct
89 Partially correct 43 ms 43000 KB Failed to provide a successful strategy.
90 Partially correct 42 ms 37964 KB Failed to provide a successful strategy.
91 Partially correct 40 ms 36760 KB Failed to provide a successful strategy.
92 Partially correct 31 ms 34012 KB Failed to provide a successful strategy.
93 Partially correct 41 ms 42372 KB Failed to provide a successful strategy.
94 Partially correct 34 ms 35568 KB Failed to provide a successful strategy.
95 Partially correct 53 ms 43612 KB Failed to provide a successful strategy.
96 Partially correct 51 ms 42968 KB Failed to provide a successful strategy.
97 Partially correct 33 ms 33356 KB Failed to provide a successful strategy.
98 Partially correct 41 ms 42712 KB Failed to provide a successful strategy.
99 Partially correct 41 ms 37196 KB Failed to provide a successful strategy.
100 Partially correct 39 ms 38264 KB Failed to provide a successful strategy.
101 Partially correct 35 ms 36716 KB Failed to provide a successful strategy.
102 Partially correct 37 ms 37020 KB Failed to provide a successful strategy.
103 Partially correct 38 ms 38684 KB Failed to provide a successful strategy.
104 Partially correct 30 ms 33020 KB Failed to provide a successful strategy.
105 Partially correct 39 ms 34876 KB Failed to provide a successful strategy.
106 Partially correct 42 ms 39628 KB Failed to provide a successful strategy.
107 Partially correct 35 ms 35368 KB Failed to provide a successful strategy.
108 Partially correct 46 ms 42976 KB Failed to provide a successful strategy.
109 Partially correct 39 ms 38224 KB Failed to provide a successful strategy.
110 Partially correct 37 ms 38092 KB Failed to provide a successful strategy.
111 Partially correct 32 ms 34724 KB Failed to provide a successful strategy.
112 Partially correct 33 ms 35668 KB Failed to provide a successful strategy.
113 Partially correct 43 ms 43084 KB Failed to provide a successful strategy.
114 Partially correct 46 ms 39684 KB Failed to provide a successful strategy.
115 Partially correct 38 ms 36016 KB Failed to provide a successful strategy.
116 Partially correct 37 ms 38996 KB Failed to provide a successful strategy.
117 Partially correct 43 ms 43448 KB Failed to provide a successful strategy.
118 Partially correct 44 ms 39868 KB Failed to provide a successful strategy.
119 Partially correct 40 ms 37324 KB Failed to provide a successful strategy.
120 Partially correct 44 ms 41012 KB Failed to provide a successful strategy.
121 Partially correct 38 ms 41044 KB Failed to provide a successful strategy.
122 Partially correct 38 ms 36436 KB Failed to provide a successful strategy.
123 Partially correct 32 ms 34756 KB Failed to provide a successful strategy.
124 Partially correct 41 ms 42852 KB Failed to provide a successful strategy.
125 Partially correct 35 ms 33192 KB Failed to provide a successful strategy.
126 Partially correct 37 ms 34640 KB Failed to provide a successful strategy.
127 Partially correct 37 ms 33784 KB Failed to provide a successful strategy.
128 Partially correct 42 ms 42708 KB Failed to provide a successful strategy.
129 Correct 39 ms 43648 KB Output is correct
130 Correct 38 ms 43596 KB Output is correct
131 Correct 39 ms 43556 KB Output is correct
132 Correct 38 ms 43596 KB Output is correct
133 Correct 44 ms 43612 KB Output is correct
134 Correct 14 ms 2504 KB Output is correct
135 Correct 11 ms 2504 KB Output is correct
136 Correct 38 ms 4640 KB Output is correct
137 Correct 20 ms 4624 KB Output is correct
138 Correct 30 ms 4624 KB Output is correct
139 Correct 54 ms 8684 KB Output is correct
140 Correct 7 ms 1484 KB Output is correct
141 Correct 4 ms 976 KB Output is correct
142 Correct 61 ms 8684 KB Output is correct
143 Correct 69 ms 8620 KB Output is correct
144 Correct 51 ms 43728 KB Output is correct
145 Correct 49 ms 43660 KB Output is correct