#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 < 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)-1 << endl;
if (n&1){
rep(j,0,2) for (int u : ve) cout << u << ' ';
return 0;
}
for (int u : ve) cout << u << ' ';
rep(i,1,n) cout << ve[i] << ' ';
return 0;
}
cout << "NO" << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
8 ms |
11988 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
7 ms |
12064 KB |
Output is correct |
3 |
Partially correct |
6 ms |
12116 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 |
11988 KB |
Output is correct |
6 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
7 ms |
11988 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
8 ms |
11972 KB |
Output is correct |
3 |
Correct |
7 ms |
11988 KB |
Output is correct |
4 |
Partially correct |
9 ms |
11988 KB |
Provide a successful but not optimal strategy. |
5 |
Partially correct |
7 ms |
12064 KB |
Provide a successful but not optimal strategy. |
6 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
7 |
Partially correct |
7 ms |
12044 KB |
Provide a successful but not optimal strategy. |
8 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
9 |
Partially correct |
8 ms |
12040 KB |
Provide a successful but not optimal strategy. |
10 |
Partially correct |
6 ms |
11988 KB |
Provide a successful but not optimal strategy. |
11 |
Partially correct |
7 ms |
12136 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 |
11988 KB |
Provide a successful but not optimal strategy. |
14 |
Partially correct |
6 ms |
12116 KB |
Provide a successful but not optimal strategy. |
15 |
Partially correct |
7 ms |
12116 KB |
Provide a successful but not optimal strategy. |
16 |
Partially correct |
7 ms |
12116 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 |
12116 KB |
Provide a successful but not optimal strategy. |
19 |
Partially correct |
6 ms |
12116 KB |
Provide a successful but not optimal strategy. |
20 |
Partially correct |
8 ms |
12068 KB |
Provide a successful but not optimal strategy. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
8 ms |
11988 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
7 ms |
12064 KB |
Output is correct |
3 |
Partially correct |
6 ms |
12116 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 |
11988 KB |
Output is correct |
6 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |