답안 #604472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604472 2022-07-25T06:49:54 Z Theo830 Newspapers (CEOI21_newspapers) C++17
54 / 100
98 ms 43852 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";
        bool ek = ans.size() % 2;
        f(i,0,n){
            if(c[i] != c[ans[0]-1] && w[i].size() == ans.size()){
                ek = 1;
                break;
            }
        }
        cout<<2 * ans.size() + (ek == 0)<<"\n";
        for(auto x:ans){
            cout<<x<<" ";
        }
        if(ans.size() % 2 == 0){
            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";
    }
}
# 결과 실행 시간 메모리 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 724 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Partially correct 1 ms 852 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 704 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 2 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 836 KB Output is correct
23 Partially correct 3 ms 1024 KB Failed to provide a successful strategy.
24 Correct 1 ms 964 KB Output is correct
25 Partially correct 1 ms 960 KB Failed to provide a successful strategy.
26 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
27 Correct 2 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 960 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 2 ms 980 KB Failed to provide a successful strategy.
34 Correct 2 ms 980 KB Output is correct
35 Correct 2 ms 1092 KB Output is correct
36 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
37 Partially correct 2 ms 1092 KB Failed to provide a successful strategy.
38 Partially correct 2 ms 1108 KB Failed to provide a successful strategy.
39 Partially correct 1 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 1096 KB Output is correct
42 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
43 Partially correct 2 ms 1084 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 2 ms 1108 KB Output is correct
47 Correct 2 ms 1236 KB Output is correct
48 Partially correct 2 ms 1236 KB Failed to provide a successful strategy.
49 Correct 3 ms 1216 KB Output is correct
50 Correct 1 ms 1236 KB Output is correct
51 Partially correct 1 ms 1236 KB Failed to provide a successful strategy.
52 Correct 2 ms 1236 KB Output is correct
53 Correct 2 ms 1236 KB Output is correct
54 Correct 2 ms 1284 KB Output is correct
55 Correct 2 ms 1236 KB Output is correct
56 Correct 2 ms 1236 KB Output is correct
57 Correct 3 ms 1212 KB Output is correct
58 Correct 2 ms 1236 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 324 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 328 KB Output is correct
63 Correct 1 ms 324 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 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 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 2 ms 852 KB Output is correct
11 Correct 78 ms 41388 KB Output is correct
12 Correct 24 ms 22712 KB Output is correct
13 Correct 32 ms 26752 KB Output is correct
14 Correct 32 ms 28352 KB Output is correct
15 Correct 33 ms 29884 KB Output is correct
16 Correct 50 ms 43596 KB Output is correct
17 Correct 56 ms 43600 KB Output is correct
18 Correct 57 ms 43576 KB Output is correct
19 Correct 50 ms 43636 KB Output is correct
20 Correct 53 ms 43724 KB Output is correct
# 결과 실행 시간 메모리 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 724 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Partially correct 1 ms 852 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 704 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 2 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 836 KB Output is correct
23 Partially correct 3 ms 1024 KB Failed to provide a successful strategy.
24 Correct 1 ms 964 KB Output is correct
25 Partially correct 1 ms 960 KB Failed to provide a successful strategy.
26 Partially correct 1 ms 980 KB Failed to provide a successful strategy.
27 Correct 2 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 960 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 2 ms 980 KB Failed to provide a successful strategy.
34 Correct 2 ms 980 KB Output is correct
35 Correct 2 ms 1092 KB Output is correct
36 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
37 Partially correct 2 ms 1092 KB Failed to provide a successful strategy.
38 Partially correct 2 ms 1108 KB Failed to provide a successful strategy.
39 Partially correct 1 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 1096 KB Output is correct
42 Partially correct 1 ms 1108 KB Failed to provide a successful strategy.
43 Partially correct 2 ms 1084 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 2 ms 1108 KB Output is correct
47 Correct 2 ms 1236 KB Output is correct
48 Partially correct 2 ms 1236 KB Failed to provide a successful strategy.
49 Correct 3 ms 1216 KB Output is correct
50 Correct 1 ms 1236 KB Output is correct
51 Partially correct 1 ms 1236 KB Failed to provide a successful strategy.
52 Correct 2 ms 1236 KB Output is correct
53 Correct 2 ms 1236 KB Output is correct
54 Correct 2 ms 1284 KB Output is correct
55 Correct 2 ms 1236 KB Output is correct
56 Correct 2 ms 1236 KB Output is correct
57 Correct 3 ms 1212 KB Output is correct
58 Correct 2 ms 1236 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 324 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 328 KB Output is correct
63 Correct 1 ms 324 KB Output is correct
64 Correct 1 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 596 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 2 ms 836 KB Output is correct
74 Partially correct 1 ms 836 KB Failed to provide a successful strategy.
75 Correct 1 ms 724 KB Output is correct
76 Partially correct 1 ms 768 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 34 ms 36168 KB Output is correct
80 Correct 38 ms 37104 KB Output is correct
81 Correct 36 ms 37580 KB Output is correct
82 Correct 38 ms 40868 KB Output is correct
83 Correct 43 ms 39116 KB Output is correct
84 Correct 37 ms 37492 KB Output is correct
85 Correct 44 ms 37440 KB Output is correct
86 Correct 45 ms 38068 KB Output is correct
87 Correct 39 ms 38988 KB Output is correct
88 Correct 31 ms 35180 KB Output is correct
89 Partially correct 47 ms 43020 KB Failed to provide a successful strategy.
90 Partially correct 47 ms 38088 KB Failed to provide a successful strategy.
91 Partially correct 52 ms 36772 KB Failed to provide a successful strategy.
92 Partially correct 32 ms 34004 KB Failed to provide a successful strategy.
93 Partially correct 46 ms 42488 KB Failed to provide a successful strategy.
94 Partially correct 36 ms 35660 KB Failed to provide a successful strategy.
95 Partially correct 44 ms 43684 KB Failed to provide a successful strategy.
96 Partially correct 48 ms 43032 KB Failed to provide a successful strategy.
97 Partially correct 41 ms 33356 KB Failed to provide a successful strategy.
98 Partially correct 56 ms 42772 KB Failed to provide a successful strategy.
99 Partially correct 38 ms 37248 KB Failed to provide a successful strategy.
100 Partially correct 39 ms 38260 KB Failed to provide a successful strategy.
101 Partially correct 43 ms 36692 KB Failed to provide a successful strategy.
102 Partially correct 37 ms 37044 KB Failed to provide a successful strategy.
103 Partially correct 41 ms 38588 KB Failed to provide a successful strategy.
104 Partially correct 32 ms 33088 KB Failed to provide a successful strategy.
105 Partially correct 36 ms 34792 KB Failed to provide a successful strategy.
106 Partially correct 43 ms 39756 KB Failed to provide a successful strategy.
107 Partially correct 41 ms 35348 KB Failed to provide a successful strategy.
108 Partially correct 46 ms 42876 KB Failed to provide a successful strategy.
109 Partially correct 45 ms 38336 KB Failed to provide a successful strategy.
110 Partially correct 37 ms 38236 KB Failed to provide a successful strategy.
111 Partially correct 39 ms 34640 KB Failed to provide a successful strategy.
112 Partially correct 37 ms 35652 KB Failed to provide a successful strategy.
113 Partially correct 49 ms 43104 KB Failed to provide a successful strategy.
114 Partially correct 41 ms 39756 KB Failed to provide a successful strategy.
115 Partially correct 36 ms 36036 KB Failed to provide a successful strategy.
116 Partially correct 39 ms 38988 KB Failed to provide a successful strategy.
117 Partially correct 47 ms 43504 KB Failed to provide a successful strategy.
118 Partially correct 45 ms 39880 KB Failed to provide a successful strategy.
119 Partially correct 43 ms 37304 KB Failed to provide a successful strategy.
120 Partially correct 52 ms 41036 KB Failed to provide a successful strategy.
121 Partially correct 49 ms 40916 KB Failed to provide a successful strategy.
122 Partially correct 35 ms 36436 KB Failed to provide a successful strategy.
123 Partially correct 32 ms 34772 KB Failed to provide a successful strategy.
124 Partially correct 53 ms 42932 KB Failed to provide a successful strategy.
125 Partially correct 30 ms 33228 KB Failed to provide a successful strategy.
126 Partially correct 41 ms 34644 KB Failed to provide a successful strategy.
127 Partially correct 43 ms 33736 KB Failed to provide a successful strategy.
128 Partially correct 47 ms 42732 KB Failed to provide a successful strategy.
129 Correct 45 ms 43588 KB Output is correct
130 Correct 70 ms 43616 KB Output is correct
131 Correct 43 ms 43648 KB Output is correct
132 Correct 47 ms 43744 KB Output is correct
133 Correct 46 ms 43580 KB Output is correct
134 Correct 20 ms 3132 KB Output is correct
135 Correct 17 ms 3096 KB Output is correct
136 Correct 39 ms 5068 KB Output is correct
137 Correct 35 ms 5212 KB Output is correct
138 Correct 55 ms 4928 KB Output is correct
139 Correct 64 ms 9028 KB Output is correct
140 Correct 10 ms 1992 KB Output is correct
141 Correct 5 ms 1160 KB Output is correct
142 Correct 70 ms 9008 KB Output is correct
143 Correct 98 ms 9032 KB Output is correct
144 Correct 55 ms 43852 KB Output is correct
145 Correct 58 ms 43768 KB Output is correct