#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define RF(n) RFi(i,n)
#define RFi(i,n) RFl(i,0,n)
#define RFl(i,l,n) for(int i=n-1;i>=l;i--)
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define mem(v,x) memset(v,x,sizeof v)
#define ff first
#define ss second
#define mid ((l+r)>>1)
#define RAN(a,b) uniform_int_distribution<int> (a, b)(rng)
template <typename T> using max_heap = __gnu_pbds::priority_queue<T,less<T> >;
template <typename T> using min_heap = __gnu_pbds::priority_queue<T,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int maxN = 1010;
vector<int> edges[maxN];
signed main(){
int n,m;
cin >> n >> m;
F(m){
int x,y;
cin >> x >> y;
edges[x].pb(y);
edges[y].pb(x);
}
if(n == 1){
printf("YES\n1\n1");
exit(0);
}
if(n == 2){
printf("YES\n2\n1 1");
exit(0);
}
if(m == n-1){
bool chain = true;
int head;
Fl(i, 1, n+1){
if(edges[i].size() > 2){
chain = false;
break;
}else{
if(edges[i].size() == 1){
head = i;
}
}
if(chain){
printf("YES\n");
printf("%d\n", 2 * (n-1));
F(n-1) printf("%d ", i+2);
F(n-1) printf("%d ", i+2);
}else{
printf("YES\n1\n1");
}
}
}else{
printf("NO\n");
}
return 0;
}
Compilation message
newspapers.cpp: In function 'int main()':
newspapers.cpp:55:9: warning: variable 'head' set but not used [-Wunused-but-set-variable]
55 | int head;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Extra information in the output file |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Extra information in the output file |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Extra information in the output file |
4 |
Halted |
0 ms |
0 KB |
- |