#include <bits/stdc++.h>
#pragma GCC target("sse,sse2")
#pragma GCC optimize("unroll-loops,O3")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 5e5+20,mod = 1e9+7,inf = 1e9+10,sq = 340;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int a,int k){
if (k < 0) return 0;
int z = 1;
while (k){
if (k&1) z = 1ll*z*a%mod;
a = 1ll*a*a%mod;
k /= 2;
}
return z;
}
vector<int> adj[N],ve;
void dfs(int v,int p){
ve.pb(v);
for (int u : adj[v]) if (u != p) dfs(u,v);
}
int main(){
ios :: sync_with_stdio(0); cin.tie(0);
int n,m;
cin >> n >> m;
if (n == 1){
cout << "YES" << endl << 1 << endl << 1;
return 0;
}
if (n-1 < m){
cout << "NO";
return 0;
}
rep(i,1,n){
int u,v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
int mx = 0;
rep(i,1,n+1) mx = max(mx,(int)adj[i].size());
if (mx == n-1){
cout << "YES" << endl << 2 << endl;
rep(i,1,n+1){
if ((int)adj[i].size() != n-1) continue;
cout << i << ' ' << i << endl;
return 0;
}
}
if (mx == 2){
cout << "YES" << endl;
rep(i,1,n+1){
if (adj[i].size() == 1){
dfs(i,0);
break;
}
}
cout << 2*n-(n&1)-2 << endl;
if (n&1){
rep(i,0,n-1) cout << ve[i] << ' ';
rep(i,1,n-1) cout << ve[i] << ' ';
return 0;
}
rep(j,0,2) rep(i,0,n-1) cout << ve[i] << ' ';
return 0;
}
int x = -1,y = -1;
rep(i,1,n){
for (int j : adj[i]){
if (adj[j].size()+adj[i].size() == n){
x = i;
y = j;
break;
}
}
}
if (x != -1){
cout << "YES" << endl << 4 << endl;
cout << x << ' ' << y << ' ' << y << ' ' << x;
return 0;
}
cout << "NO" << endl;
return 0;
}
Compilation message
newspapers.cpp: In function 'int main()':
newspapers.cpp:86:45: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
86 | if (adj[j].size()+adj[i].size() == n){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
11988 KB |
Output is correct |
3 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
5 |
Correct |
6 ms |
12048 KB |
Output is correct |
6 |
Correct |
6 ms |
12020 KB |
Output is correct |
7 |
Correct |
6 ms |
12060 KB |
Output is correct |
8 |
Incorrect |
6 ms |
12044 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Partially correct |
7 ms |
11988 KB |
Provide a successful but not optimal strategy. |
5 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
6 |
Partially correct |
7 ms |
12052 KB |
Provide a successful but not optimal strategy. |
7 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
8 |
Partially correct |
6 ms |
12040 KB |
Provide a successful but not optimal strategy. |
9 |
Partially correct |
7 ms |
11988 KB |
Provide a successful but not optimal strategy. |
10 |
Partially correct |
9 ms |
11988 KB |
Provide a successful but not optimal strategy. |
11 |
Partially correct |
7 ms |
12116 KB |
Provide a successful but not optimal strategy. |
12 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
13 |
Partially correct |
7 ms |
12092 KB |
Provide a successful but not optimal strategy. |
14 |
Partially correct |
8 ms |
12044 KB |
Provide a successful but not optimal strategy. |
15 |
Partially correct |
8 ms |
12088 KB |
Provide a successful but not optimal strategy. |
16 |
Partially correct |
8 ms |
12016 KB |
Provide a successful but not optimal strategy. |
17 |
Partially correct |
8 ms |
12116 KB |
Provide a successful but not optimal strategy. |
18 |
Partially correct |
7 ms |
12132 KB |
Provide a successful but not optimal strategy. |
19 |
Partially correct |
9 ms |
12116 KB |
Provide a successful but not optimal strategy. |
20 |
Partially correct |
7 ms |
12116 KB |
Provide a successful but not optimal strategy. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
11988 KB |
Output is correct |
3 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
5 |
Correct |
6 ms |
12048 KB |
Output is correct |
6 |
Correct |
6 ms |
12020 KB |
Output is correct |
7 |
Correct |
6 ms |
12060 KB |
Output is correct |
8 |
Incorrect |
6 ms |
12044 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |